//package com.fowo.api.inventory.service.impl;
//
//import cn.hutool.core.collection.CollUtil;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.fowo.api.entity.WarehouseBin;
//import com.fowo.api.entity.WarehouseBinProducts;
//import com.fowo.api.inventory.config.*;
//import com.fowo.api.inventory.entity.*;
//import com.fowo.api.inventory.mapper.*;
//import com.fowo.api.inventory.model.*;
//import com.fowo.api.inventory.model.form.InventoryExchangeFormVo;
//import com.fowo.api.inventory.model.form.InventoryOutboundFormVo;
//import com.fowo.api.inventory.model.form.InventoryStorageFormVo;
//import com.fowo.api.inventory.service.*;
//import com.fowo.api.service.WarehouseBinRulesService;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.collections4.CollectionUtils;
//import org.apache.commons.lang3.ObjectUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.jeecgframework.minidao.util.SnowflakeIdWorker;
//import org.springframework.beans.BeanUtils;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.TransactionDefinition;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.util.StopWatch;
//
//import javax.annotation.Resource;
//import java.math.BigDecimal;
//import java.text.DateFormat;
//import java.text.SimpleDateFormat;
//import java.util.*;
//import java.util.stream.Collectors;
//
//@Service
//@Slf4j
//public class InventoryBusinessServiceImpl2 extends ServiceImpl<InventoryMapper, Inventory> implements InventoryBusinessService2 {
//    @Resource
//    private DataSourceTransactionManager dataSourceTransactionManager;
//    @Resource
//    private TransactionDefinition transactionDefinition;
//    //主库存表
//    @Resource
//    private InventoryMapper inventoryMapper;
//    // 库存变动表
//    @Resource
//    private InventoryVariationMapper inventoryVariationMapper;
//
//    @Resource
//    private InventoryVariationService inventoryVariationService;
//    //库存货位放置表
//    @Resource
//    private InventoryPlacementMapper inventoryPlacementMapper;
//    @Resource
//    private InventoryPlacementService inventoryPlacementService;
//    //余额表表
//    @Resource
//    private InventoryMonthlyMapper inventoryMonthlyMapper;
//    //批次库存表
//    @Resource
//    private InventoryBatchNoMapper inventoryBatchNoMapper;
//    @Resource
//    private InventoryBatchNoService inventoryBatchNoService;
//    //库位变动表
//    @Resource
//    private InventoryPlacementVariationMapper inventoryPlacementVariationMapper;
//    @Resource
//    private InventoryPlacementVariationService inventoryPlacementVariationService;
//    //可用库存
//    @Resource
//    private WarehouseBinRulesService warehouseBinRulesService;
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public InventoryListReturnVo storage(InventoryStorageFormVo model) throws Exception {
//        if (model.getItems() == null || model.getItems().isEmpty()) {
//            throw new Exception("项目不能为空！");
//        }
//        if (StringUtils.isEmpty(model.getOperateKey())) {
//            // 使用雪花算法生成操作统一键
//            model.setOperateKey(SnowflakeIdWorker.generateId().toString());
//        }
//        if (ObjectUtils.isNotEmpty(model.getOrderDate())) {
//            //如果单据时间小于结账日期 不予操作
//            if (StringUtils.isNotEmpty(CarryDateConfig.sql)) {
//                Date date = inventoryMapper.selectCarryDate(CarryDateConfig.sql);
//                if (ObjectUtils.isNotEmpty(date)) {
//                    if (model.getOrderDate().getTime() < date.getTime()) {
//                        throw new Exception("单据日期小于结账日期 不允许库存入库");
//                    }
//                }
//            }
//        }
//        List<InventoryStorageVo> itemsList = new ArrayList<>();
//        // 将表单属性填充到项中
//        for (InventoryStorageVo item : model.getItems()) {
//            if (Boolean.TRUE.equals(model.getReverseQtySign())) {
//                item.setQty(item.getQty().negate());
//                if (item.getBinIds() != null && item.getBinIds().size() != 0) {
//                    for (Long key : item.getBinIds().keySet()) {
//                        item.getBinIds().put(key, 0 - item.getBinIds().get(key));
//                    }
//                }
//            }
//            item.setDocumentType(model.getDocumentType());
//            item.setSupportNegative(model.getSupportNegative());
//            item.setStockId(model.getStockId());
//            item.setTo(model.getTo());
//            item.setOperate(model.getOperate());
//            item.setFormNum(model.getFormNum());
//            item.setFormOperator(model.getFormOperator());
//            item.setOperateKey(model.getOperateKey());
////            //如果启用批次号 放入唯一批次号
////            if(model.getBatchManagement()){
////                item.setBatchNo(createBatchNo());
////            }
//            if (item.getUserData1() == null) {
//                item.setUserData1(model.getUserData1());
//            }
//            if (item.getUserData2() == null) {
//                item.setUserData2(model.getUserData2());
//            }
//            if (item.getUserData3() == null) {
//                item.setUserData3(model.getUserData3());
//            }
//            if (item.getUserData4() == null) {
//                item.setUserData4(model.getUserData4());
//            }
//            if (item.getUserData5() == null) {
//                item.setUserData5(model.getUserData5());
//            }
//            if (item.getUserData6() == null) {
//                item.setUserData6(model.getUserData6());
//            }
//            if (item.getUserData7() == null) {
//                item.setUserData7(model.getUserData7());
//            }
//            if (item.getUserData8() == null) {
//                item.setUserData8(model.getUserData8());
//            }
//            if (item.getRemark() == null) {
//                item.setRemark(model.getRemark());
//            }
//            itemsList.add(item);
//        }
//        List<Long> items = model.getItems().stream().map(m -> m.getItem().getId()).collect(Collectors.toList());
//        List<Long> stockIds = model.getItems().stream().map(m -> m.getStockId()).collect(Collectors.toList());
//        List<WarehouseBinProducts> warehouseBinProductsList = warehouseBinRulesService.searchWarehouseBinProductsList(items);
//        List<Long> parentIds = warehouseBinProductsList.stream().map(m -> m.getParentId()).collect(Collectors.toList());
//        //根据子表查询得数据+仓库
//        List<WarehouseBin> zzWarehouseBinList = new ArrayList<>();
//        //根据仓库查询  1  可用暂存  2 次品暂存 3 可用 4 次品
//        List<WarehouseBin> zWarehouseBinList = new ArrayList<>();
//        if (model.getTo().getValue().equals(TargetTypeVo.Defect)) {
//            if (CollectionUtils.isNotEmpty(parentIds)) {
//                zzWarehouseBinList = warehouseBinRulesService.searchWarehouseBinList(parentIds, stockIds, 2);
//            }
//            zWarehouseBinList = warehouseBinRulesService.searchWarehouseBinByWarehouseIdList(stockIds, 2);
//        } else {
//            if (CollectionUtils.isNotEmpty(parentIds)) {
//                zzWarehouseBinList = warehouseBinRulesService.searchWarehouseBinList(parentIds, stockIds, 1);
//            }
//            zWarehouseBinList = warehouseBinRulesService.searchWarehouseBinByWarehouseIdList(stockIds, 1);
//        }
//        //处理 仓位null 得数据填充
//        for (InventoryStorageVo inventoryStorageVo : itemsList) {
//            if (inventoryStorageVo.getBinIds() != null && inventoryStorageVo.getBinIds().size() > 0) {
//                Map<Long, Integer> binIds1 = inventoryStorageVo.getBinIds();
//                Map<Long, Integer> update = new HashMap<>();
//                for (Long key : binIds1.keySet()) {
//                    if (ObjectUtils.isEmpty(key)) {
//                        List<WarehouseBinProducts> filterwarehouseBinProductsList = this.getFilterWarehouseProductsBinList(warehouseBinProductsList, inventoryStorageVo);
//                        if (CollectionUtils.isEmpty(filterwarehouseBinProductsList)) {
//                            Long binKey = this.getFilterWarehouseBinList(zWarehouseBinList, inventoryStorageVo);
//                            update.put(binKey, binIds1.get(key));
//                        } else {
//                            Long binKey = this.getFilterWarehouseBinListByParentId(filterwarehouseBinProductsList, zzWarehouseBinList, zWarehouseBinList, inventoryStorageVo);
//                            update.put(binKey, binIds1.get(key));
//                        }
//                    }
//                }
//                if (update.size() != 0) {
//                    inventoryStorageVo.setBinIds(update);
//                }
//            }
//        }
//        //数据根据维度分组
//        Map<String, List<InventoryStorageVo>> listMap = itemsList
//                .stream()
//                .collect(Collectors.groupingBy(item -> this.inventoryGroupingBy(item)
//                ));
//
//        //数据根据维度合并
//        List<InventoryStorageVo> finalFormInventoryStorageVoList = new ArrayList<>();
//        listMap.forEach((key, valueList) -> {
//            if (valueList.size() == 1) {
//                finalFormInventoryStorageVoList.addAll(valueList);
//            } else {
//                InventoryStorageVo inventoryStorageVo = this.numMergeInventoryStorageVo(valueList);
//                finalFormInventoryStorageVoList.add(inventoryStorageVo);
//            }
//
//        });
//        InventoryListReturnVo returnVo = new InventoryListReturnVo();
//
//        try {
//            List<String> errList = new ArrayList<>();
//            List<Inventory> list = inventoryMapper.selectByStorageList(items);
//            List<InventoryPlacement> list1 = new ArrayList<>();
//            List<InventoryBatchNo> list2 = new ArrayList<>();
//
//            List<InventoryVariation> inventoryVariations = new ArrayList<>();
//            List<InventoryPlacementVariation> inventoryPlacementVariations = new ArrayList<>();
//
//            List<InventoryBatchNo> inventoryBatchNo = new ArrayList<>();
//            List<InventoryBatchNo> updateInventoryBatchNoList = new ArrayList<>();
//
//            List<Inventory> insertInventory = new ArrayList<>();
//            List<Inventory> updateInventoryList = new ArrayList<>();
//
//            List<InventoryPlacement> insertInventoryPlacement = new ArrayList<>();
//            List<InventoryPlacement> updateInventoryPlacementList = new ArrayList<>();
//            if (model.getItems().get(0).getBinIds() != null && model.getItems().get(0).getBinIds().size() != 0) {
//                list1 = inventoryPlacementMapper.selectByStorageList(items);
//            }
//            if (StockAgeConfig.isOpen) {
//                list2 = inventoryBatchNoMapper.selectByStorageList(items);
//            }
//            StopWatch stopWatch = new StopWatch("测试秒表");
//            stopWatch.start("数据处理");
//            for (InventoryStorageVo item : finalFormInventoryStorageVoList) {
//                try {
//                    final InventoryListReturnVo inventoryListReturnVo = storageItem(item, list, list1, list2);
//                    if (inventoryListReturnVo.getInventoryVariations() != null) {
//                        inventoryVariations.add(inventoryListReturnVo.getInventoryVariations());
//                    }
//                    if (inventoryListReturnVo.getInventoryPlacementVariations() != null && inventoryListReturnVo.getInventoryPlacementVariations().size() != 0) {
//                        inventoryPlacementVariations.addAll(inventoryListReturnVo.getInventoryPlacementVariations());
//                    }
//
//                    if (inventoryListReturnVo.getInventory() != null) {
//                        insertInventory.add(inventoryListReturnVo.getInventory());
//                    }
//                    if (inventoryListReturnVo.getUpdateInventoryList() != null && inventoryListReturnVo.getUpdateInventoryList().size() > 0) {
//                        updateInventoryList.addAll(inventoryListReturnVo.getUpdateInventoryList());
//                    }
//                    if (inventoryListReturnVo.getInventoryBatchNo() != null) {
//                        inventoryBatchNo.add(inventoryListReturnVo.getInventoryBatchNo());
//                    }
//                    if (inventoryListReturnVo.getUpdateInventoryBatchNoList() != null && inventoryListReturnVo.getUpdateInventoryBatchNoList().size() > 0) {
//                        updateInventoryBatchNoList.addAll(inventoryListReturnVo.getUpdateInventoryBatchNoList());
//                    }
//                    if (inventoryListReturnVo.getInventoryPlacement() != null && inventoryListReturnVo.getInventoryPlacement().size() > 0) {
//                        insertInventoryPlacement.addAll(inventoryListReturnVo.getInventoryPlacement());
//                    }
//                    if (inventoryListReturnVo.getUpdateInventoryPlacementList() != null && inventoryListReturnVo.getUpdateInventoryPlacementList().size() > 0) {
//                        updateInventoryPlacementList.addAll(inventoryListReturnVo.getUpdateInventoryPlacementList());
//                    }
//                    returnVo.add(inventoryListReturnVo);
//                } catch (Exception e) {
//                    System.out.println(e.getMessage());
//                    e.printStackTrace();
//                    errList.add(e.getMessage());
//                    throw e;
//
//                }
//            }
//            stopWatch.stop();
//            if (CollUtil.isNotEmpty(errList)) {
//                throw new Exception(StringUtils.join(errList, ";"));
//            }
//            //批量添加流水
//            stopWatch.start("数据处理--库存流水");
//            if (inventoryVariations.size() > 0) {
//                inventoryVariationService.saveBatch(inventoryVariations);
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--仓位流水");
//            if (inventoryPlacementVariations.size() > 0) {
//                inventoryPlacementVariationService.saveBatch(inventoryPlacementVariations);
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--库龄修改");
//            if (updateInventoryBatchNoList.size() > 0) {
//                if (inventoryBatchNoMapper.updateBatch(updateInventoryBatchNoList) < 1) {
//                    throw new Exception("库存更新失败，库存可能在操作期间变更");
//                }
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--仓位修改");
//            if (updateInventoryPlacementList.size() > 0) {
//                if (inventoryPlacementMapper.updateBatch(updateInventoryPlacementList) < 1) {
//                    throw new Exception("库存更新失败，库存可能在操作期间变更");
//                }
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--库龄添加");
//            if (inventoryBatchNo.size() > 0) {
//                inventoryBatchNoService.saveBatch(inventoryBatchNo);
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--库存修改");
//            if (updateInventoryList.size() > 0) {
//                if (this.baseMapper.updateBatch(updateInventoryList) < 1) {
//                    throw new Exception("库存更新失败，库存可能在操作期间变更");
//                }
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--仓位添加");
//            if (insertInventoryPlacement.size() > 0) {
//                inventoryPlacementService.saveBatch(insertInventoryPlacement);
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--库存添加");
//            if (insertInventory.size() > 0) {
//                this.saveBatch(insertInventory);
//            }
//            stopWatch.stop();
//            stopWatch.setKeepTaskList(true); //是否构建TaskInfo信息
//
//            Arrays.stream(stopWatch.getTaskInfo()).forEach(sw ->
//
//                    System.out.println(sw.getTaskName() + " " +
//                            sw.getTimeMillis() + " " + sw.getTimeSeconds()));
//
//
//            System.out.println(stopWatch.isRunning());
//
//            System.out.println(stopWatch.prettyPrint());//打印详细信息
//
//            System.out.println(stopWatch.shortSummary());//打印简要信息
//            System.out.println("成功");
//        } catch (Exception e) {
//            throw e;
//        }
//        return returnVo;
//    }
//
//
//    @Transactional(rollbackFor = Exception.class)
//    @Override
//    public InventoryListReturnVo outbound(InventoryOutboundFormVo model) throws Exception {
//        if(model.getItems() == null || model.getItems().isEmpty()) {
//            throw new Exception("项目不能为空！");
//        }
//        if (StringUtils.isEmpty(model.getOperateKey())) {
//            // 使用雪花算法生成操作统一键
//            model.setOperateKey(SnowflakeIdWorker.generateId().toString());
//        }
//        if (ObjectUtils.isNotEmpty(model.getOrderDate())) {
//            //如果单据时间小于结账日期 不予操作
//            if (StringUtils.isNotEmpty(CarryDateConfig.sql)) {
//                Date date=inventoryMapper.selectCarryDate(CarryDateConfig.sql);
//                if (ObjectUtils.isNotEmpty(date)) {
//                    if(model.getOrderDate().getTime()<date.getTime()){
//                        throw new Exception("单据日期小于结账日期 不允许库存出库");
//                    }
//                }
//            }
//        }
//        List<InventoryOutboundVo> itemsList = new ArrayList<>();
//        // 将表单属性填充到项中
//        for (InventoryOutboundVo item : model.getItems()) {
//            if (Boolean.TRUE.equals(model.getReverseQtySign())) {
//                item.setQty(item.getQty().negate());
//                if(item.getBinIds()!=null&&item.getBinIds().size()!=0){
//                    for(Long key:item.getBinIds().keySet()){
//                        item.getBinIds().put(key,0-item.getBinIds().get(key));
//                    }
//                }
//            }
//            item.setDocumentType(model.getDocumentType());
//            item.setSupportNegative(model.getSupportNegative());
//            item.setFormNum(model.getFormNum());
//            item.setFormOperator(model.getFormOperator());
//            item.setOperate(model.getOperate());
//            item.setOperateKey(model.getOperateKey());
//            item.setStockId(model.getStockId());
//            item.setModel(model.getModel());
//            item.setFrom(model.getFrom());
//            if (item.getUserData1() == null) {
//                item.setUserData1(model.getUserData1());
//            }
//            if (item.getUserData2() == null) {
//                item.setUserData2(model.getUserData2());
//            }
//            if (item.getUserData3() == null) {
//                item.setUserData3(model.getUserData3());
//            }
//            if (item.getUserData4() == null) {
//                item.setUserData4(model.getUserData4());
//            }
//            if (item.getUserData5() == null) {
//                item.setUserData5(model.getUserData5());
//            }
//            if (item.getUserData6() == null) {
//                item.setUserData6(model.getUserData6());
//            }
//            if (item.getUserData7() == null) {
//                item.setUserData7(model.getUserData7());
//            }
//            if (item.getUserData8() == null) {
//                item.setUserData8(model.getUserData8());
//            }
//            if (item.getRemark() == null) {
//                item.setRemark(model.getRemark());
//            }
//            itemsList.add(item);
//        }
//        List<Long> items = model.getItems().stream().map(m -> m.getItem().getId()).collect(Collectors.toList());
//        List<Long> stockIds = model.getItems().stream().map(m -> m.getStockId()).collect(Collectors.toList());
//        List<WarehouseBinProducts> warehouseBinProductsList = warehouseBinRulesService.searchWarehouseBinProductsList(items);
//        List<Long> parentIds = warehouseBinProductsList.stream().map(m -> m.getParentId()).collect(Collectors.toList());
//        //根据子表查询得数据+仓库
//        List<WarehouseBin> zzWarehouseBinList = new ArrayList<>();
//        //根据仓库查询
//        List<WarehouseBin> zWarehouseBinList = new ArrayList<>();
//        if (model.getFrom().getValue().equals(TargetTypeVo.Defect)) {
//            if (CollectionUtils.isNotEmpty(parentIds)) {
//                zzWarehouseBinList = warehouseBinRulesService.searchWarehouseBinList(parentIds, stockIds, 2);
//            }
//            zWarehouseBinList = warehouseBinRulesService.searchWarehouseBinByWarehouseIdList(stockIds, 2);
//        } else {
//            if (CollectionUtils.isNotEmpty(parentIds)) {
//                zzWarehouseBinList = warehouseBinRulesService.searchWarehouseBinList(parentIds, stockIds, 1);
//            }
//            zWarehouseBinList = warehouseBinRulesService.searchWarehouseBinByWarehouseIdList(stockIds, 1);
//        }
//        //处理 仓位null 得数据填充
//        for (InventoryOutboundVo inventoryStorageVo : itemsList) {
//            if (inventoryStorageVo.getBinIds() != null && inventoryStorageVo.getBinIds().size() > 0) {
//                Map<Long, Integer> binIds1 = inventoryStorageVo.getBinIds();
//                Map<Long, Integer> update = new HashMap<>();
//                for (Long key : binIds1.keySet()) {
//                    if (ObjectUtils.isEmpty(key)) {
//                        List<WarehouseBinProducts> filterwarehouseBinProductsList = this.getOutFilterWarehouseProductsBinList(warehouseBinProductsList, inventoryStorageVo);
//                        if (CollectionUtils.isEmpty(filterwarehouseBinProductsList)) {
//                            Long binKey = this.getOutFilterWarehouseBinList(zWarehouseBinList, inventoryStorageVo);
//                            update.put(binKey, binIds1.get(key));
//                        } else {
//                            Long binKey = this.getOutFilterWarehouseBinListByParentId(filterwarehouseBinProductsList, zzWarehouseBinList, zWarehouseBinList, inventoryStorageVo);
//                            update.put(binKey, binIds1.get(key));
//                        }
//                    }
//                }
//                if (update.size() != 0) {
//                    inventoryStorageVo.setBinIds(update);
//                }
//            }
//        }
//        //数据根据维度分组
//        Map<String, List<InventoryOutboundVo>> listMap = itemsList
//                .stream()
//                .collect(Collectors.groupingBy(item -> this.outInventoryGroupingBy(item)
//                ));
//
//        //数据根据维度合并
//        List<InventoryOutboundVo> finalFormInventoryStorageVoList = new ArrayList<>();
//        listMap.forEach((key, valueList) -> {
//            if (valueList.size() == 1) {
//                finalFormInventoryStorageVoList.addAll(valueList);
//            } else {
//                InventoryOutboundVo inventoryStorageVo = this.outNumMergeInventoryStorageVo(valueList);
//                finalFormInventoryStorageVoList.add(inventoryStorageVo);
//            }
//        });
//        InventoryListReturnVo returnVo = new InventoryListReturnVo();
//
//        try {
//            Boolean b = false;
//            List<String> err = new ArrayList<>();
//            List<Inventory> list = inventoryMapper.selectByStorageList(items);
//            List<InventoryPlacement> list1 = new ArrayList<>();
//            List<InventoryBatchNo> list2 = new ArrayList<>();
//
//            List<InventoryVariation> inventoryVariations = new ArrayList<>();
//            List<InventoryPlacementVariation> inventoryPlacementVariations = new ArrayList<>();
//
//            List<InventoryBatchNo> inventoryBatchNo = new ArrayList<>();
//            List<InventoryBatchNo> updateInventoryBatchNoList = new ArrayList<>();
//
//            List<Inventory> insertInventory = new ArrayList<>();
//            List<Inventory> updateInventoryList = new ArrayList<>();
//
//            List<InventoryPlacement> insertInventoryPlacement = new ArrayList<>();
//            List<InventoryPlacement> updateInventoryPlacementList = new ArrayList<>();
//            if (model.getItems().get(0).getBinIds() != null && model.getItems().get(0).getBinIds().size() != 0) {
//                list1 = inventoryPlacementMapper.selectByStorageList(items);
//            }
//            if (StockAgeConfig.isOpen) {
//                list2 = inventoryBatchNoMapper.selectByStorageList(items);
//            }
//            StopWatch stopWatch = new StopWatch("测试秒表");
//            stopWatch.start("数据处理");
//            for (InventoryOutboundVo item : finalFormInventoryStorageVoList) {
//                try {
//                    final InventoryListReturnVo inventoryListReturnVo = outboundItem(item, list, list1, list2);
//                    if (inventoryListReturnVo.getInsertInventoryVariations() != null&& inventoryListReturnVo.getInsertInventoryVariations().size() != 0) {
//                        inventoryVariations.addAll(inventoryListReturnVo.getInsertInventoryVariations());
//                    }
//                    if (inventoryListReturnVo.getInventoryVariations() != null) {
//                        inventoryVariations.add(inventoryListReturnVo.getInventoryVariations());
//                    }
//                    if (inventoryListReturnVo.getInventoryPlacementVariations() != null && inventoryListReturnVo.getInventoryPlacementVariations().size() != 0) {
//                        inventoryPlacementVariations.addAll(inventoryListReturnVo.getInventoryPlacementVariations());
//                    }
//                    if (inventoryListReturnVo.getInventory() != null) {
//                        insertInventory.add(inventoryListReturnVo.getInventory());
//                    }
//                    if (inventoryListReturnVo.getUpdateInventoryList() != null && inventoryListReturnVo.getUpdateInventoryList().size() > 0) {
//                        updateInventoryList.addAll(inventoryListReturnVo.getUpdateInventoryList());
//                    }
//                    if (inventoryListReturnVo.getInventoryBatchNo() != null) {
//                        inventoryBatchNo.add(inventoryListReturnVo.getInventoryBatchNo());
//                    }
//                    if (inventoryListReturnVo.getUpdateInventoryBatchNoList() != null && inventoryListReturnVo.getUpdateInventoryBatchNoList().size() > 0) {
//                        updateInventoryBatchNoList.addAll(inventoryListReturnVo.getUpdateInventoryBatchNoList());
//                    }
//                    if (inventoryListReturnVo.getInventoryPlacement() != null && inventoryListReturnVo.getInventoryPlacement().size() > 0) {
//                        insertInventoryPlacement.addAll(inventoryListReturnVo.getInventoryPlacement());
//                    }
//                    if (inventoryListReturnVo.getUpdateInventoryPlacementList() != null && inventoryListReturnVo.getUpdateInventoryPlacementList().size() > 0) {
//                        updateInventoryPlacementList.addAll(inventoryListReturnVo.getUpdateInventoryPlacementList());
//                    }
//                    returnVo.add(inventoryListReturnVo);
//                } catch (Exception e) {
//                    System.out.println(e.getMessage());
//                    e.printStackTrace();
//                    b = true;
//                    err.add(e.getMessage());
//                    throw e;
//                }
//            }
//            stopWatch.stop();
//            if (b) {
//                throw new Exception(StringUtils.join(err, ";"));
//            }
//            //批量添加流水
//            stopWatch.start("数据处理--库存流水");
//            if (inventoryVariations.size() > 0) {
//                inventoryVariationService.saveBatch(inventoryVariations);
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--仓位流水");
//            if (inventoryPlacementVariations.size() > 0) {
//                inventoryPlacementVariationService.saveBatch(inventoryPlacementVariations);
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--库龄修改");
//            if (updateInventoryBatchNoList.size() > 0) {
//                if (inventoryBatchNoMapper.updateBatch(updateInventoryBatchNoList) < 1) {
//                    throw new Exception("库存更新失败，库存可能在操作期间变更");
//                }
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--仓位修改");
//            if (updateInventoryPlacementList.size() > 0) {
//                if (inventoryPlacementMapper.updateBatch(updateInventoryPlacementList) < 1) {
//                    throw new Exception("库存更新失败，库存可能在操作期间变更");
//                }
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--库龄添加");
//            if (inventoryBatchNo.size() > 0) {
//                inventoryBatchNoService.saveBatch(inventoryBatchNo);
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--库存修改");
//            if (updateInventoryList.size() > 0) {
//                if (this.baseMapper.updateBatch(updateInventoryList) < 1) {
//                    throw new Exception("库存更新失败，库存可能在操作期间变更");
//                }
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--仓位添加");
//            if (insertInventoryPlacement.size() > 0) {
//                inventoryPlacementService.saveBatch(insertInventoryPlacement);
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--库存添加");
//            if (insertInventory.size() > 0) {
//                this.saveBatch(insertInventory);
//            }
//            stopWatch.stop();
//            stopWatch.setKeepTaskList(true); //是否构建TaskInfo信息
//
//            Arrays.stream(stopWatch.getTaskInfo()).forEach(sw ->
//
//                    System.out.println(sw.getTaskName() + " " +
//                            sw.getTimeMillis() + " " + sw.getTimeSeconds()));
//
//
//            System.out.println(stopWatch.isRunning());
//
//            System.out.println(stopWatch.prettyPrint());//打印详细信息
//
//            System.out.println(stopWatch.shortSummary());//打印简要信息
//            System.out.println("成功");
//        } catch (Exception e) {
//            throw e;
//        }
//        return returnVo;
//
//    }
//
//    @Transactional(rollbackFor = Exception.class)
//    @Override
//    public InventoryListReturnVo exchange(InventoryExchangeFormVo model) throws Exception {
//        if(model.getItems() == null || model.getItems().isEmpty()) {
//            throw new Exception("项目不能为空！");
//        }
//        if (StringUtils.isEmpty(model.getOperateKey())) {
//            // 使用雪花算法生成操作统一键
//            model.setOperateKey(SnowflakeIdWorker.generateId().toString());
//        }
//        if (ObjectUtils.isNotEmpty(model.getOrderDate())) {
//            //如果单据时间小于结账日期 不予操作
//            if (StringUtils.isNotEmpty(CarryDateConfig.sql)) {
//                Date date=inventoryMapper.selectCarryDate(CarryDateConfig.sql);
//                if (ObjectUtils.isNotEmpty(date)) {
//                    if(model.getOrderDate().getTime()<date.getTime()){
//                        throw new Exception("单据日期小于结账日期 不允库存流转");
//                    }
//                }
//            }
//        }
//        List<InventoryExchangeVo> itemsList=new ArrayList<>();
//        // 将表单属性填充到项中
//        for (InventoryExchangeVo item : model.getItems()) {
//            if (Boolean.TRUE.equals(model.getReverseQtySign())) {
//                item.setQty(item.getQty().negate());
//                if(item.getToBinIds()!=null&&item.getToBinIds().size()!=0){
//                    for(Long key:item.getToBinIds().keySet()){
//                        item.getToBinIds().put(key,0-item.getToBinIds().get(key));
//                    }
//                }
//                if(item.getFromBinIds()!=null&&item.getFromBinIds().size()!=0){
//                    for(Long key:item.getFromBinIds().keySet()){
//                        item.getFromBinIds().put(key,0-item.getFromBinIds().get(key));
//                    }
//                }
//            }
//            item.setDocumentType(model.getDocumentType());
//            item.setSupportNegative(model.getSupportNegative());
//            item.setFormNum(model.getFormNum());
//            item.setFormOperator(model.getFormOperator());
//            item.setOperate(model.getOperate());
//            item.setOperate(model.getOperate());
//            item.setOperateKey(model.getOperateKey());
//            item.setFromStockId(model.getFromStockId());
//            item.setToStockId(model.getToStockId());
//            item.setFromStockId(model.getFromStockId());
//            item.setFrom(model.getFrom());
//            item.setTo(model.getTo());
//            item.setModel(model.getModel());
//            if (item.getUserData1() == null) {
//                item.setUserData1(model.getUserData1());
//            }
//            if (item.getUserData2() == null) {
//                item.setUserData2(model.getUserData2());
//            }
//            if (item.getUserData3() == null) {
//                item.setUserData3(model.getUserData3());
//            }
//            if (item.getUserData4() == null) {
//                item.setUserData4(model.getUserData4());
//            }
//            if (item.getUserData5() == null) {
//                item.setUserData5(model.getUserData5());
//            }
//            if (item.getUserData6() == null) {
//                item.setUserData6(model.getUserData6());
//            }
//            if (item.getUserData7() == null) {
//                item.setUserData7(model.getUserData7());
//            }
//            if (item.getUserData8() == null) {
//                item.setUserData8(model.getUserData8());
//            }
//            if (item.getRemark() == null) {
//                item.setRemark(model.getRemark());
//            }
//            itemsList.add(item);
//        }
//        List<Long> items = model.getItems().stream().map(m -> m.getItem().getId()).collect(Collectors.toList());
//        List<Long> toStockIds = model.getItems().stream().map(m -> m.getToStockId()).collect(Collectors.toList());
//        List<Long> fromStockIds = model.getItems().stream().map(m -> m.getFromStockId()).collect(Collectors.toList());
//        List<Long> stockIds = new ArrayList<>();
//        stockIds.addAll(toStockIds);
//        stockIds.addAll(fromStockIds);
//        stockIds=stockIds.stream().distinct().collect(Collectors.toList());
//        List<WarehouseBinProducts> warehouseBinProductsList = warehouseBinRulesService.searchWarehouseBinProductsList(items);
//        List<Long> parentIds = warehouseBinProductsList.stream().map(m -> m.getParentId()).collect(Collectors.toList());
//        //根据子表查询得数据+仓库
//        List<WarehouseBin> zzWarehouseBinList = new ArrayList<>();
//        //根据仓库查询
//        List<WarehouseBin> zWarehouseBinList = new ArrayList<>();
//        if (model.getFrom().getValue().equals(TargetTypeVo.Defect)) {
//            if (CollectionUtils.isNotEmpty(parentIds)) {
//                zzWarehouseBinList = warehouseBinRulesService.searchWarehouseBinList(parentIds, stockIds, 2);
//            }
//            zWarehouseBinList = warehouseBinRulesService.searchWarehouseBinByWarehouseIdList(stockIds, 2);
//        } else {
//            if (CollectionUtils.isNotEmpty(parentIds)) {
//                zzWarehouseBinList = warehouseBinRulesService.searchWarehouseBinList(parentIds, stockIds, 1);
//            }
//            zWarehouseBinList = warehouseBinRulesService.searchWarehouseBinByWarehouseIdList(stockIds, 1);
//        }
//        //处理 仓位null 得数据填充
//        for (InventoryExchangeVo inventoryStorageVo : itemsList) {
//            if (inventoryStorageVo.getFromBinIds() != null && inventoryStorageVo.getFromBinIds().size() > 0) {
//                Map<Long, Integer> binIds1 = inventoryStorageVo.getFromBinIds();
//                Map<Long, Integer> update = new HashMap<>();
//                for (Long key : binIds1.keySet()) {
//                    if (ObjectUtils.isEmpty(key)) {
//                        List<WarehouseBinProducts> filterwarehouseBinProductsList = this.getExchangeFilterWarehouseProductsBinList(warehouseBinProductsList, inventoryStorageVo);
//                        if (CollectionUtils.isEmpty(filterwarehouseBinProductsList)) {
//                            Long binKey = this.getExchangeFilterWarehouseBinList(zWarehouseBinList, inventoryStorageVo,1);
//                            update.put(binKey, binIds1.get(key));
//                        } else {
//                            Long binKey = this.getExchangeFilterWarehouseBinListByParentId(filterwarehouseBinProductsList, zzWarehouseBinList, zWarehouseBinList, inventoryStorageVo,1);
//                            update.put(binKey, binIds1.get(key));
//                        }
//                    }
//                }
//                if (update.size() != 0) {
//                    inventoryStorageVo.setFromBinIds(update);
//                }
//            }
//            if (inventoryStorageVo.getToBinIds() != null && inventoryStorageVo.getToBinIds().size() > 0) {
//                Map<Long, Integer> binIds1 = inventoryStorageVo.getToBinIds();
//                Map<Long, Integer> update = new HashMap<>();
//                for (Long key : binIds1.keySet()) {
//                    if (ObjectUtils.isEmpty(key)) {
//                        List<WarehouseBinProducts> filterwarehouseBinProductsList = this.getExchangeFilterWarehouseProductsBinList(warehouseBinProductsList, inventoryStorageVo);
//                        if (CollectionUtils.isEmpty(filterwarehouseBinProductsList)) {
//                            Long binKey = this.getExchangeFilterWarehouseBinList(zWarehouseBinList, inventoryStorageVo,2);
//                            update.put(binKey, binIds1.get(key));
//                        } else {
//                            Long binKey = this.getExchangeFilterWarehouseBinListByParentId(filterwarehouseBinProductsList, zzWarehouseBinList, zWarehouseBinList, inventoryStorageVo,2);
//                            update.put(binKey, binIds1.get(key));
//                        }
//                    }
//                }
//                if (update.size() != 0) {
//                    inventoryStorageVo.setToBinIds(update);
//                }
//            }
//        }
//        //数据根据维度分组
//        Map<String, List<InventoryExchangeVo>> listMap = itemsList
//                .stream()
//                .collect(Collectors.groupingBy(item -> this.exchangInventoryGroupingBy(item)
//                ));
//
//        //数据根据维度合并
//        List<InventoryExchangeVo> finalFormInventoryStorageVoList = new ArrayList<>();
//        listMap.forEach((key, valueList) -> {
//            if (valueList.size() == 1) {
//                finalFormInventoryStorageVoList.addAll(valueList);
//            } else {
//                InventoryExchangeVo inventoryStorageVo = this.exchangeNumMergeInventoryStorageVo(valueList);
//                finalFormInventoryStorageVoList.add(inventoryStorageVo);
//            }
//        });
//        InventoryListReturnVo returnVo = new InventoryListReturnVo();
//        List<Inventory> list = inventoryMapper.selectByStorageList(items);
//        List<InventoryPlacement> list1 = new ArrayList<>();
//        List<InventoryBatchNo> list2 = new ArrayList<>();
//
//        List<InventoryVariation> inventoryVariations = new ArrayList<>();
//        List<InventoryPlacementVariation> inventoryPlacementVariations = new ArrayList<>();
//
//        List<InventoryBatchNo> inventoryBatchNo = new ArrayList<>();
//        List<InventoryBatchNo> updateInventoryBatchNoList = new ArrayList<>();
//
//        List<Inventory> insertInventory = new ArrayList<>();
//        List<Inventory> updateInventoryList = new ArrayList<>();
//
//        List<InventoryPlacement> insertInventoryPlacement = new ArrayList<>();
//        List<InventoryPlacement> updateInventoryPlacementList = new ArrayList<>();
//        if (model.getItems().get(0).getFromBinIds() != null && model.getItems().get(0).getFromBinIds().size() != 0) {
//            list1 = inventoryPlacementMapper.selectByStorageList(items);
//        }
//        if (StockAgeConfig.isOpen) {
//            list2 = inventoryBatchNoMapper.selectByStorageList(items);
//        }
//        try {
//            Boolean b=false;
//            List<String> err=new ArrayList<>();
//            for (InventoryExchangeVo item : finalFormInventoryStorageVoList) {
//                try {
//                    final  InventoryListReturnVo inventoryListReturnVo=exchangeItem(item,list,list1,list2);
//                    if (inventoryListReturnVo.getInsertInventoryVariations() != null&& inventoryListReturnVo.getInsertInventoryVariations().size() != 0) {
//                        inventoryVariations.addAll(inventoryListReturnVo.getInsertInventoryVariations());
//                    }
//                    if (inventoryListReturnVo.getInventoryVariations() != null) {
//                        inventoryVariations.add(inventoryListReturnVo.getInventoryVariations());
//                    }
//
//                    if (inventoryListReturnVo.getInventoryPlacementVariations() != null && inventoryListReturnVo.getInventoryPlacementVariations().size() != 0) {
//                        inventoryPlacementVariations.addAll(inventoryListReturnVo.getInventoryPlacementVariations());
//                    }
//                    if (inventoryListReturnVo.getInventory() != null) {
//                        insertInventory.add(inventoryListReturnVo.getInventory());
//                    }
//                    if (inventoryListReturnVo.getInsertInventory() != null) {
//                        insertInventory.addAll(inventoryListReturnVo.getInsertInventory());
//                    }
//                    if (inventoryListReturnVo.getUpdateInventoryList() != null && inventoryListReturnVo.getUpdateInventoryList().size() > 0) {
//                        updateInventoryList.addAll(inventoryListReturnVo.getUpdateInventoryList());
//                    }
//                    if (inventoryListReturnVo.getInventoryBatchNo() != null) {
//                        inventoryBatchNo.add(inventoryListReturnVo.getInventoryBatchNo());
//                    }
//                    if (inventoryListReturnVo.getInsertInventoryBatchNo() != null&&inventoryListReturnVo.getInsertInventoryBatchNo().size()!=0) {
//                        inventoryBatchNo.addAll(inventoryListReturnVo.getInsertInventoryBatchNo());
//                    }
//                    if (inventoryListReturnVo.getUpdateInventoryBatchNoList() != null && inventoryListReturnVo.getUpdateInventoryBatchNoList().size() > 0) {
//                        updateInventoryBatchNoList.addAll(inventoryListReturnVo.getUpdateInventoryBatchNoList());
//                    }
//                    if (inventoryListReturnVo.getInventoryPlacement() != null && inventoryListReturnVo.getInventoryPlacement().size() > 0) {
//                        insertInventoryPlacement.addAll(inventoryListReturnVo.getInventoryPlacement());
//                    }
//                    if (inventoryListReturnVo.getUpdateInventoryPlacementList() != null && inventoryListReturnVo.getUpdateInventoryPlacementList().size() > 0) {
//                        updateInventoryPlacementList.addAll(inventoryListReturnVo.getUpdateInventoryPlacementList());
//                    }
//                    System.out.println(inventoryListReturnVo);
//                }catch (Exception e){
//                    b=true;
//                    err.add(e.getMessage());
//                    e.printStackTrace();
//                    throw e;
//                }
//            }
//
//            //数据处理
//            if(b){
//                throw new Exception(StringUtils.join(err,";"));
//            }
//
//            StopWatch stopWatch = new StopWatch("测试秒表");
//            //批量添加流水
//            stopWatch.start("数据处理--库存流水");
//            if (inventoryVariations.size() > 0) {
//                inventoryVariationService.saveBatch(inventoryVariations);
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--仓位流水");
//            if (inventoryPlacementVariations.size() > 0) {
//                inventoryPlacementVariationService.saveBatch(inventoryPlacementVariations);
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--库龄修改");
//            if (updateInventoryBatchNoList.size() > 0) {
//                if (inventoryBatchNoMapper.updateBatch(updateInventoryBatchNoList) < 1) {
//                    throw new Exception("库存更新失败，库存可能在操作期间变更");
//                }
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--仓位修改");
//            if (updateInventoryPlacementList.size() > 0) {
//                if (inventoryPlacementMapper.updateBatch(updateInventoryPlacementList) < 1) {
//                    throw new Exception("库存更新失败，库存可能在操作期间变更");
//                }
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--库龄添加");
//            if (inventoryBatchNo.size() > 0) {
//                inventoryBatchNoService.saveBatch(inventoryBatchNo);
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--库存修改");
//            if (updateInventoryList.size() > 0) {
//                if (this.baseMapper.updateBatch(updateInventoryList) < 1) {
//                    throw new Exception("库存更新失败，库存可能在操作期间变更");
//                }
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--仓位添加");
//            if (insertInventoryPlacement.size() > 0) {
//                inventoryPlacementService.saveBatch(insertInventoryPlacement);
//            }
//            stopWatch.stop();
//            stopWatch.start("数据处理--库存添加");
//            if (insertInventory.size() > 0) {
//                this.saveBatch(insertInventory);
//            }
//            stopWatch.stop();
//            stopWatch.setKeepTaskList(true); //是否构建TaskInfo信息
//
//            Arrays.stream(stopWatch.getTaskInfo()).forEach(sw ->
//
//                    System.out.println(sw.getTaskName() + " " +
//                            sw.getTimeMillis() + " " + sw.getTimeSeconds()));
//
//
//            System.out.println(stopWatch.isRunning());
//
//            System.out.println(stopWatch.prettyPrint());//打印详细信息
//
//            System.out.println(stopWatch.shortSummary());//打印简要信息
//            System.out.println("成功");
//        } catch (Exception e) {
//
//            throw e;
//        }
//        return returnVo;
//    }
//    private InventoryExchangeVo exchangeNumMergeInventoryStorageVo(List<InventoryExchangeVo> valueList) {
//        InventoryExchangeVo inventoryStorageVo = valueList.get(0);
//        BigDecimal sumQty = valueList.stream().map(InventoryExchangeVo::getQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        inventoryStorageVo.setQty(sumQty);
//        Map<String, List<InventoryExchangeVo>> listMap = valueList
//                .stream()
//                .collect(Collectors.groupingBy(item -> this.exchangeInventoryBinIdsGroupingBy(item,1)
//                ));
//        Map<Long, Integer> fromBinIds = new HashMap<>();
//        listMap.forEach((key, itemList) -> {
//            if (!ObjectUtils.isEmpty(key)) {
//                if (itemList.size() == 1) {
//                    fromBinIds.putAll(itemList.get(0).getFromBinIds());
//                } else {
//                    Integer sum = 0;
//                    for (InventoryExchangeVo storageVo : itemList) {
//                        Map<Long, Integer> binIds1 = storageVo.getFromBinIds();
//                        for (Long key1 : binIds1.keySet()) {
//                            sum = sum + binIds1.get(key1);
//                        }
//                    }
//                    fromBinIds.put(Long.valueOf(key), sum);
//                }
//            }
//
//        });
//        inventoryStorageVo.setFromBinIds(fromBinIds);
//        Map<String, List<InventoryExchangeVo>> listMap1 = valueList
//                .stream()
//                .collect(Collectors.groupingBy(item -> this.exchangeInventoryBinIdsGroupingBy(item,2)
//                ));
//        Map<Long, Integer> toBinIds = new HashMap<>();
//        listMap.forEach((key, itemList) -> {
//            if (!ObjectUtils.isEmpty(key)) {
//                if (itemList.size() == 1) {
//                    toBinIds.putAll(itemList.get(0).getToBinIds());
//                } else {
//                    Integer sum = 0;
//                    for (InventoryExchangeVo storageVo : itemList) {
//                        Map<Long, Integer> binIds1 = storageVo.getToBinIds();
//                        for (Long key1 : binIds1.keySet()) {
//                            sum = sum + binIds1.get(key1);
//                        }
//                    }
//                    toBinIds.put(Long.valueOf(key), sum);
//                }
//            }
//
//        });
//        inventoryStorageVo.setToBinIds(toBinIds);
//        return inventoryStorageVo;
//    }
//
//    private String exchangeInventoryBinIdsGroupingBy(InventoryExchangeVo item, int i) {
//        String binid = "";
//        if(i==1){
//            if (item.getFromBinIds() != null && item.getFromBinIds().size() != 0) {
//                for (Long key : item.getFromBinIds().keySet()) {
//                    binid = binid + key;
//                }
//            }
//        }else {
//            if (item.getToBinIds() != null && item.getToBinIds().size() != 0) {
//                for (Long key : item.getToBinIds().keySet()) {
//                    binid = binid + key;
//                }
//            }
//        }
//        return binid;
//    }
//
//    private String exchangInventoryGroupingBy(InventoryExchangeVo item) {
//        String groupingBy = "";
//        if (ObjectUtils.isNotEmpty(item.getItem().getId())) {
//            groupingBy = groupingBy + item.getItem().getId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getFromStockId())) {
//            groupingBy = groupingBy + item.getFromStockId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getToStockId())) {
//            groupingBy = groupingBy + item.getToStockId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getFnSku())) {
//            groupingBy = groupingBy + item.getFnSku();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getItem().getId())) {
//            groupingBy = groupingBy + item.getItem().getId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getBatchNo())) {
//            groupingBy = groupingBy + item.getBatchNo();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getShopId())) {
//            groupingBy = groupingBy + item.getShopId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getProjectId())) {
//            groupingBy = groupingBy + item.getProjectId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        return groupingBy;
//    }
//
//    private Long getExchangeFilterWarehouseBinListByParentId(List<WarehouseBinProducts> filterwarehouseBinProductsList, List<WarehouseBin> zzWarehouseBinList, List<WarehouseBin> zWarehouseBinList, InventoryExchangeVo inventoryStorageVo, int type) throws Exception {
//        List<Long> ids = filterwarehouseBinProductsList.stream().map(s -> s.getParentId()).collect(Collectors.toList());
//        zzWarehouseBinList = zzWarehouseBinList.stream().filter(s -> ids.contains(s.getId())).collect(Collectors.toList());
//        if (CollectionUtils.isEmpty(zzWarehouseBinList)) {
//            return this.getExchangeFilterWarehouseBinList(zWarehouseBinList, inventoryStorageVo,type);
//        } else {
//            return zzWarehouseBinList.get(0).getId();
//        }
//    }
//
//    private InventoryListReturnVo exchangeItem(InventoryExchangeVo model,List<Inventory> list ,List<InventoryPlacement> list1 ,List<InventoryBatchNo> list2 ) throws Exception{
//        getDocumentType(model.getDocumentType());
//        verificationExchange(model);
//        List<BinIdsVo> fromBinIdsVos =new ArrayList<>();
//        if( model.getQty().compareTo(BigDecimal.ZERO)==0){
//            return new InventoryListReturnVo();
//        }
//        if (null!=model.getFromBinIds()&&model.getFromBinIds().size()>0){
//            fromBinIdsVos= model.getFromBinIds().entrySet().stream().map(c -> new BinIdsVo(c.getKey(), c.getValue())).collect(Collectors.toList());
//            long sum = fromBinIdsVos.stream().mapToLong(BinIdsVo::getQty).sum();
//            if(QtyIsZeroConfig.isOpen){
//                if(model.getQty().compareTo(BigDecimal.ZERO)==0){
//                    return new InventoryListReturnVo();
//                }
//                if (model.getQty().longValue()!=sum){
//                    throw new Exception("fromBindIds 为非空时，所有入位数量合计不等于qty");
//                }
//            }else if(sum<=0 || model.getQty().longValue()!=sum){
//                throw new Exception("fromBindIds 为非空时，所有入位数量大于0并且合计不等于qty");
//            }
//        }
//        List<BinIdsVo> toBinIdsVos =new ArrayList<>();
//        if (null!=model.getToBinIds()&&model.getToBinIds().size()>0){
//            toBinIdsVos= model.getToBinIds().entrySet().stream().map(c -> new BinIdsVo(c.getKey(), c.getValue())).collect(Collectors.toList());
//            long sum = toBinIdsVos.stream().mapToLong(BinIdsVo::getQty).sum();
//            if(QtyIsZeroConfig.isOpen){
//                if(model.getQty().compareTo(BigDecimal.ZERO)==0){
//                    return new InventoryListReturnVo();
//                }
//                if (model.getQty().longValue()!=sum){
//                    throw new Exception("toBindIds 为非空时，所有入位数量合计不等于qty");
//                }
//            }else if(sum<=0 || model.getQty().longValue()!=sum){
//                throw new Exception("toBindIds 为非空时，所有入位数量大于0并且合计不等于qty");
//            }
//        }
////        仓库内移货位
////        条件为： fromStockId == toStockId && from == to && fromBinIds != null && toBinIds != null
////        按给出的业务唯一标识，选择模式，fromBinIds 选择满足条件的from库存记录
////        按给出的业务唯一标识，选择模式，toBinIds 选择满足条件的to库存记录
////        减少 from 的库存数，添加到对应 to 的库存数中，如果对应 to 库存记录不存在就新增
//        if(model.getFromStockId().equals(model.getToStockId())){
//            if (model.getFrom().equals(model.getTo())&&model.getFromBinIds()!=null&&model.getToBinIds()!=null) {
//                return exchangeShift(model, fromBinIdsVos, toBinIdsVos,list1);
//            } else if (!model.getFrom().equals(model.getTo())) {
//                InventoryListReturnVo inventoryListReturnVo=new InventoryListReturnVo();
//                if(StockAgeConfig.isOpen){
//                    // 批次库存数量转换
//                    exchangeTargetTypeBatchNo(model,list2,inventoryListReturnVo);
//                }
//                return exchangeTargetType(model,list,inventoryListReturnVo);
//            }
//        }
////        跨库调拨
////        条件为 fromStockId != toStockId
////        此情况 exchange 自动完成分别调用出仓的 outbound 和入仓的 storage，对应变更的 operate（操作名称）自动配置为 “调拨出库”与“调拨入库”
//        if(!model.getFromStockId().equals(model.getToStockId())){
//            //通过配置 是做库存还是批次库存不用改
//            return exchangeAllot(model,list,list1,list2);
//
//        }
//        return new InventoryListReturnVo();
//    }
//
//    private InventoryListReturnVo exchangeAllot(InventoryExchangeVo model, List<Inventory> list, List<InventoryPlacement> list1, List<InventoryBatchNo> list2) throws Exception {
//        //出库
//        InventoryOutboundVo inventoryOutboundVo=new InventoryOutboundVo();
//        BeanUtils.copyProperties(model,inventoryOutboundVo);
//        inventoryOutboundVo.setOperate("调拨出库");
//        inventoryOutboundVo.setStockId(model.getFromStockId());
//        inventoryOutboundVo.setBinIds(model.getFromBinIds());
//        InventoryListReturnVo outbound= outboundItem(inventoryOutboundVo,list,list1,list2);
//
//        //入库 入库需要
//        InventoryStorageVo inventoryStorageVo=new InventoryStorageVo();
//        BeanUtils.copyProperties(model,inventoryStorageVo);
//        inventoryStorageVo.setOperate("调拨入库");
//        inventoryStorageVo.setStockId(model.getToStockId());
//        inventoryStorageVo.setBinIds(model.getToBinIds());
//        InventoryListReturnVo storage = storageItem(inventoryStorageVo,list,list1,list2);
//
//        InventoryListReturnVo inventoryListReturnVo=new InventoryListReturnVo();
//
//        List<Inventory> insertInventory=new ArrayList<>();
//        List<Inventory> updateInventoryList=new ArrayList<>();
//
//        List<InventoryBatchNo> inventoryBatchNo=new ArrayList<>();
//        List<InventoryBatchNo> updateInventoryBatchNoList=new ArrayList<>();
//
//        List<InventoryPlacement> inventoryPlacement=new ArrayList<>();
//        List<InventoryPlacement> updateInventoryPlacementList=new ArrayList<>();
//
//        List<InventoryPlacementVariation> inventoryPlacementVariations=new ArrayList<>();
//        List<InventoryVariation> inventoryVariations=new ArrayList<>();
//
//        //库存流水
//        if (outbound.getInsertInventoryVariations() != null&& outbound.getInsertInventoryVariations().size() != 0) {
//            inventoryVariations.addAll(outbound.getInsertInventoryVariations());
//        }
//        if (outbound.getInventoryVariations() != null) {
//            inventoryVariations.add(outbound.getInventoryVariations());
//        }
//
//        //仓位流水
//        if (outbound.getInventoryPlacementVariations() != null && outbound.getInventoryPlacementVariations().size() != 0) {
//            inventoryPlacementVariations.addAll(outbound.getInventoryPlacementVariations());
//        }
//
//        //库存
//        if (outbound.getInventory() != null) {
//            insertInventory.add(outbound.getInventory());
//        }
//        if (outbound.getInsertInventory() != null&&outbound.getInsertInventory().size()!=0) {
//            insertInventory.addAll(outbound.getInsertInventory());
//        }
//        if (outbound.getUpdateInventoryList() != null && outbound.getUpdateInventoryList().size() > 0) {
//            updateInventoryList.addAll(outbound.getUpdateInventoryList());
//        }
//
//        //库龄
//        if (outbound.getInventoryBatchNo() != null) {
//            inventoryBatchNo.add(outbound.getInventoryBatchNo());
//        }
//        if (outbound.getInsertInventoryBatchNo() != null&&outbound.getInsertInventoryBatchNo().size()!=0) {
//            inventoryBatchNo.addAll(outbound.getInsertInventoryBatchNo());
//        }
//        if (outbound.getUpdateInventoryBatchNoList() != null && outbound.getUpdateInventoryBatchNoList().size() > 0) {
//            updateInventoryBatchNoList.addAll(outbound.getUpdateInventoryBatchNoList());
//        }
//
//        //仓位
//        if (storage.getInventoryPlacement() != null && storage.getInventoryPlacement().size() > 0) {
//            inventoryPlacement.addAll(storage.getInventoryPlacement());
//        }
//        if (storage.getUpdateInventoryPlacementList() != null && storage.getUpdateInventoryPlacementList().size() > 0) {
//            updateInventoryPlacementList.addAll(storage.getUpdateInventoryPlacementList());
//        }
//        //库存流水
//        if (storage.getInsertInventoryVariations() != null&& storage.getInsertInventoryVariations().size() != 0) {
//            inventoryVariations.addAll(storage.getInsertInventoryVariations());
//        }
//        if (storage.getInventoryVariations() != null) {
//            inventoryVariations.add(storage.getInventoryVariations());
//        }
//
//        //仓位流水
//        if (storage.getInventoryPlacementVariations() != null && storage.getInventoryPlacementVariations().size() != 0) {
//            inventoryPlacementVariations.addAll(storage.getInventoryPlacementVariations());
//        }
//
//        //库存
//        if (storage.getInventory() != null) {
//            insertInventory.add(storage.getInventory());
//        }
//        if (storage.getInsertInventory() != null&&storage.getInsertInventory().size()!=0) {
//            insertInventory.addAll(storage.getInsertInventory());
//        }
//        if (storage.getUpdateInventoryList() != null && storage.getUpdateInventoryList().size() > 0) {
//            updateInventoryList.addAll(storage.getUpdateInventoryList());
//        }
//
//        //库龄
//        if (storage.getInventoryBatchNo() != null) {
//            inventoryBatchNo.add(storage.getInventoryBatchNo());
//        }
//        if (storage.getInsertInventoryBatchNo() != null&&storage.getInsertInventoryBatchNo().size()!=0) {
//            inventoryBatchNo.addAll(storage.getInsertInventoryBatchNo());
//        }
//        if (storage.getUpdateInventoryBatchNoList() != null && storage.getUpdateInventoryBatchNoList().size() > 0) {
//            updateInventoryBatchNoList.addAll(storage.getUpdateInventoryBatchNoList());
//        }
//
//        //仓位
//        if (storage.getInventoryPlacement() != null && storage.getInventoryPlacement().size() > 0) {
//            inventoryPlacement.addAll(storage.getInventoryPlacement());
//        }
//        if (storage.getUpdateInventoryPlacementList() != null && storage.getUpdateInventoryPlacementList().size() > 0) {
//            updateInventoryPlacementList.addAll(storage.getUpdateInventoryPlacementList());
//        }
//
//        inventoryListReturnVo.setInsertInventoryBatchNo(inventoryBatchNo);
//        inventoryListReturnVo.setUpdateInventoryBatchNoList(updateInventoryBatchNoList);
//
//
//        inventoryListReturnVo.setInventoryPlacement(inventoryPlacement);
//        inventoryListReturnVo.setUpdateInventoryPlacementList(updateInventoryPlacementList);
//
//        inventoryListReturnVo.setInsertInventoryVariations(inventoryVariations);
//        inventoryListReturnVo.setInventoryPlacementVariations(inventoryPlacementVariations);
//
//        inventoryListReturnVo.setUpdateInventoryList(updateInventoryList);
//        inventoryListReturnVo.setInsertInventory(insertInventory);
//
//        return inventoryListReturnVo;
//    }
//
//    private InventoryListReturnVo exchangeTargetType(InventoryExchangeVo model, List<Inventory> list, InventoryListReturnVo inventoryListReturnVo) throws Exception {
//        if (model.getFromBinIds() != null || model.getToBinIds() != null) {
//            if(model.getFromBinIds().size() != 0||model.getToBinIds().size() !=0 ){
//                throw new Exception("此操作目前不支持带库位处理!");
//            }
//        }
//        boolean IsOpenNegativeInventory = getIsOpenNegativeInventory(model.getFromStockId());
//        List<Inventory> inventoryList = getExchangeInventory(model, list);
//        if (CollectionUtils.isEmpty(inventoryList)) {
//            if (IsOpenNegativeInventory) {
//                throw new Exception(getItemIdName(model.getItem().getId()) + "要操作的源库存不存在！");
//            } else {
//                //添加新的 在处理
//                Inventory inventoryStorageVo = new Inventory();
//                BeanUtils.copyProperties(model, inventoryStorageVo);
//                inventoryStorageVo.setStockId(model.getFromStockId());
//                storageExchangeInsert(model,inventoryStorageVo,inventoryListReturnVo);
//
//            }
//        }else {
//            if (IsOpenNegativeInventory) {
//                verificationOexchangeTargetType(model, inventoryList);
//            }
//            BigDecimal qtySum = model.getQty();
//            List<InventoryVariation> inventoryVariationList=new ArrayList<>();
//            List<Inventory> updateInventoryList = new ArrayList<>();
//            for (Inventory inventory : inventoryList) {
//                //需要处理的数量
//                BigDecimal num = model.getQty();
//                if (qtySum.compareTo(BigDecimal.ZERO) == 0) {
//                    //库存都处理完
//                    break;
//                }
//                ChangeNum stockQty = new ChangeNum(inventory.getStockQty());
//                ChangeNum lockQty = new ChangeNum(inventory.getLockQty());
//                ChangeNum displayQty = new ChangeNum(inventory.getDisplayQty());
//                ChangeNum defectQty = new ChangeNum(inventory.getDefectQty());
//                ChangeNum wayQty = new ChangeNum(inventory.getWayQty());
//                ChangeNum storageQty = new ChangeNum(inventory.getStorageQty());
//                ChangeNum rejectLockQty = new ChangeNum(inventory.getRejectLockQty());
//                ChangeNum rejectWayQty = new ChangeNum(inventory.getRejectWayQty());
//                ChangeNum inspectedQty = new ChangeNum(inventory.getInspectedQty());
//                ChangeNum pickingQty = new ChangeNum(inventory.getPickingQty());
//                InventoryVariation inventoryVariation = new InventoryVariation();
//                BeanUtils.copyProperties(model, inventoryVariation);
//                inventoryVariation.setChangeType("Exchange");
//                inventoryVariation.setStockId(model.getFromStockId());
//                inventoryVariation.setFromType(model.getFrom().getValue());
//                inventoryVariation.setToType(model.getTo().getValue());
//                inventoryVariation.setItemId(model.getItem().getId());
//                inventoryVariation.setOperateTime(new Date());
//
//                Inventory updateInventory = new Inventory();
//                updateInventory.setId(inventory.getId());
//                updateInventory.setVersion(inventory.getVersion());
//                // 处理出
//                switch (model.getFrom().getValue()) {
//                    case TargetTypeVo.Normal:
//                        if (!IsOpenNegativeInventory) {
//                            stockQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (stockQty.getValue().compareTo(qtySum) >= 0) {
//                            num = qtySum;
//                            stockQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num = stockQty.getValue();
//                            qtySum = qtySum.subtract(stockQty.getValue());
//                            stockQty.subtract(stockQty.getValue());
//
//                        }
//                        break;
//                    case TargetTypeVo.Display:
//                        if (!IsOpenNegativeInventory) {
//                            stockQty.subtract(model.getQty());
//                            displayQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (displayQty.getValue().compareTo(qtySum) >= 0) {
//                            num = qtySum;
//                            stockQty.subtract(qtySum);
//                            displayQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num = displayQty.getValue();
//                            qtySum = qtySum.subtract(stockQty.getValue());
//                            stockQty.subtract(stockQty.getValue());
//                            displayQty.subtract(displayQty.getValue());
//                        }
//
//                        break;
//                    case TargetTypeVo.Defect:
//                        if (!IsOpenNegativeInventory) {
//                            stockQty.subtract(model.getQty());
//                            defectQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (defectQty.getValue().compareTo(qtySum) >= 0) {
//                            num = qtySum;
//                            stockQty.subtract(qtySum);
//                            defectQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num = defectQty.getValue();
//                            qtySum = qtySum.subtract(stockQty.getValue());
//                            stockQty.subtract(stockQty.getValue());
//                            defectQty.subtract(defectQty.getValue());
//
//                        }
//                        break;
//                    case TargetTypeVo.Lock:
//                        if (!IsOpenNegativeInventory) {
//                            stockQty.subtract(model.getQty());
//                            lockQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (lockQty.getValue().compareTo(qtySum) >= 0) {
//                            num = qtySum;
//                            stockQty.subtract(qtySum);
//                            lockQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num = lockQty.getValue();
//                            qtySum = qtySum.subtract(stockQty.getValue());
//                            stockQty.subtract(stockQty.getValue());
//                            lockQty.subtract(lockQty.getValue());
//
//                        }
//                        break;
//                    case TargetTypeVo.Way:
//                        if (!IsOpenNegativeInventory) {
//                            wayQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (wayQty.getValue().compareTo(qtySum) >= 0) {
//                            num = qtySum;
//                            wayQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num = wayQty.getValue();
//                            qtySum = qtySum.subtract(wayQty.getValue());
//                            wayQty.subtract(wayQty.getValue());
//
//                        }
//                        break;
//                    case TargetTypeVo.Storage:
//                        if (!IsOpenNegativeInventory) {
//                            storageQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (storageQty.getValue().compareTo(qtySum) >= 0) {
//                            num = qtySum;
//                            storageQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num = storageQty.getValue();
//                            qtySum = qtySum.subtract(storageQty.getValue());
//                            storageQty.subtract(storageQty.getValue());
//
//                        }
//                        break;
//                    case TargetTypeVo.RejectLock:
//                        if (!IsOpenNegativeInventory) {
//                            rejectLockQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (rejectLockQty.getValue().compareTo(qtySum) >= 0) {
//                            num = qtySum;
//                            rejectLockQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num = rejectLockQty.getValue();
//                            qtySum = qtySum.subtract(rejectLockQty.getValue());
//                            rejectLockQty.subtract(rejectLockQty.getValue());
//
//                        }
//                        // storageQty.subtract(model.getQty());
//                        break;
//                    case TargetTypeVo.RejectWay:
//                        if (!IsOpenNegativeInventory) {
//                            rejectWayQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (rejectWayQty.getValue().compareTo(qtySum) >= 0) {
//                            num = qtySum;
//                            rejectWayQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num = rejectWayQty.getValue();
//                            qtySum = qtySum.subtract(rejectWayQty.getValue());
//                            rejectWayQty.subtract(rejectWayQty.getValue());
//
//                        }
//                        break;
//                    case TargetTypeVo.Inspected:
//                        if (!IsOpenNegativeInventory) {
//                            inspectedQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (inspectedQty.getValue().compareTo(qtySum) >= 0) {
//                            num = qtySum;
//                            inspectedQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num = inspectedQty.getValue();
//                            qtySum = qtySum.subtract(inspectedQty.getValue());
//                            inspectedQty.subtract(inspectedQty.getValue());
//                        }
//                        break;
//                    case TargetTypeVo.Picking:
//                        if (!IsOpenNegativeInventory) {
//                            pickingQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (pickingQty.getValue().compareTo(qtySum) >= 0) {
//                            num = qtySum;
//                            pickingQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num = pickingQty.getValue();
//                            qtySum = qtySum.subtract(pickingQty.getValue());
//                            pickingQty.subtract(pickingQty.getValue());
//
//                        }
//                        break;
//                }
//
//                // 处理入
//                switch (model.getTo().getValue()) {
//                    case TargetTypeVo.Normal:
//                        stockQty.add(num);
//                        break;
//                    case TargetTypeVo.Display:
//                        stockQty.add(num);
//                        displayQty.add(num);
//                        break;
//                    case TargetTypeVo.Defect:
//                        stockQty.add(num);
//                        defectQty.add(num);
//                        break;
//                    case TargetTypeVo.Lock:
//                        stockQty.add(num);
//                        lockQty.add(num);
//                        break;
//                    case TargetTypeVo.Way:
//                        wayQty.add(num);
//                        break;
//                    case TargetTypeVo.Storage:
//                        storageQty.add(num);
//                        break;
//                    case TargetTypeVo.RejectLock:
//                        rejectLockQty.add(num);
//                        break;
//                    case TargetTypeVo.RejectWay:
//                        rejectWayQty.add(num);
//                        break;
//                    case TargetTypeVo.Inspected:
//                        inspectedQty.add(num);
//                        break;
//                    case TargetTypeVo.Picking:
//                        pickingQty.add(num);
//                        break;
//                }
//
//                updateInventory.setStockQty(stockQty.getValue());
//                inventoryVariation.setStockQty(stockQty.getValue());
//                inventoryVariation.setChangeStockQty(stockQty.getChange());
//                updateInventory.setLockQty(lockQty.getValue());
//                inventoryVariation.setLockQty(lockQty.getValue());
//                inventoryVariation.setChangeLockQty(lockQty.getChange());
//                updateInventory.setWayQty(wayQty.getValue());
//                inventoryVariation.setWayQty(wayQty.getValue());
//                inventoryVariation.setChangeWayQty(wayQty.getChange());
//                updateInventory.setDisplayQty(displayQty.getValue());
//                inventoryVariation.setDisplayQty(displayQty.getValue());
//                inventoryVariation.setChangeDisplayQty(displayQty.getChange());
//                updateInventory.setDefectQty(defectQty.getValue());
//                inventoryVariation.setDefectQty(defectQty.getValue());
//                inventoryVariation.setChangeDefectQty(defectQty.getChange());
//                updateInventory.setStorageQty(storageQty.getValue());
//                inventoryVariation.setStorageQty(storageQty.getValue());
//                inventoryVariation.setChangeStorageQty(storageQty.getChange());
//                updateInventory.setRejectLockQty(rejectLockQty.getValue());
//                inventoryVariation.setRejectLockQty(rejectLockQty.getValue());
//                inventoryVariation.setChangeRejectLockQty(rejectLockQty.getChange());
//                updateInventory.setRejectWayQty(rejectWayQty.getValue());
//                inventoryVariation.setRejectWayQty(rejectWayQty.getValue());
//                inventoryVariation.setChangeRejectWayQty(rejectWayQty.getChange());
//                updateInventory.setInspectedQty(inspectedQty.getValue());
//                inventoryVariation.setInspectedQty(inspectedQty.getValue());
//                inventoryVariation.setChangeInspectedQty(inspectedQty.getChange());
//                updateInventory.setPickingQty(pickingQty.getValue());
//                inventoryVariation.setPickingQty(pickingQty.getValue());
//                inventoryVariation.setChangePickingQty(pickingQty.getChange());
//                updateInventoryList.add(updateInventory);
//                inventoryVariationList.add(inventoryVariation);
//            }
//            inventoryListReturnVo.setUpdateInventoryList(updateInventoryList);
//            inventoryListReturnVo.setInsertInventoryVariations(inventoryVariationList);
//        }
//        return inventoryListReturnVo;
//    }
//
//    private void storageExchangeInsert(InventoryExchangeVo model, Inventory inventory, InventoryListReturnVo inventoryListReturnVo) {
//        inventory.setStockId(model.getFromStockId());
//        inventory.setItemId(model.getItem().getId());
//        if (StringUtils.isBlank(model.getBatchNo())) {
//            inventory.setBatchNo(null);
//        }
//        // 处理出
//        switch (model.getFrom().getValue()) {
//            case TargetTypeVo.Normal:
//                inventory.setStockQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.Display:
//                inventory.setDisplayQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.Defect:
//                inventory.setDefectQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.Lock:
//                inventory.setLockQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.Way:
//                inventory.setWayQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.Storage:
//                inventory.setStorageQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.RejectLock:
//                inventory.setRejectLockQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.RejectWay:
//                inventory.setRejectWayQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.Inspected:
//                inventory.setInspectedQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.Picking:
//                inventory.setPickingQty(model.getQty().negate());
//                break;
//        }
//
//        // 处理入
//        switch (model.getTo().getValue()) {
//            case TargetTypeVo.Normal:
//                inventory.setStockQty(model.getQty());
//                break;
//            case TargetTypeVo.Display:
//                inventory.setDisplayQty(model.getQty());
//                break;
//            case TargetTypeVo.Defect:
//                inventory.setDefectQty(model.getQty());
//                break;
//            case TargetTypeVo.Lock:
//                inventory.setLockQty(model.getQty());
//                break;
//            case TargetTypeVo.Way:
//                inventory.setWayQty(model.getQty());
//                break;
//            case TargetTypeVo.Storage:
//                inventory.setStorageQty(model.getQty());
//                break;
//            case TargetTypeVo.RejectLock:
//                inventory.setRejectLockQty(model.getQty());
//                break;
//            case TargetTypeVo.RejectWay:
//                inventory.setRejectWayQty(model.getQty());
//                break;
//            case TargetTypeVo.Inspected:
//                inventory.setInspectedQty(model.getQty());
//                break;
//            case TargetTypeVo.Picking:
//                inventory.setPickingQty(model.getQty());
//                break;
//        }
//        inventoryListReturnVo.setInventory(inventory);
//    }
//
//    private void verificationOexchangeTargetType(InventoryExchangeVo model, List<Inventory> inventoryList)  throws Exception{
//        {
//            //校验库存是否有那么多
//            BigDecimal stockQty = inventoryList.stream().filter(c -> c.getStockQty() != null).map(Inventory::getStockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//            BigDecimal lockQty = inventoryList.stream().filter(c -> c.getLockQty() != null).map(Inventory::getLockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//            BigDecimal detDefectQty = inventoryList.stream().filter(c -> c.getDefectQty() != null).map(Inventory::getDefectQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//            BigDecimal displayQty = inventoryList.stream().filter(c -> c.getDisplayQty() != null).map(Inventory::getDisplayQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//            BigDecimal wayQty = inventoryList.stream().filter(c -> c.getWayQty() != null).map(Inventory::getWayQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//            BigDecimal storageQty = inventoryList.stream().filter(c -> c.getStorageQty() != null).map(Inventory::getStorageQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//            BigDecimal rejectLockQty = inventoryList.stream().filter(c -> c.getRejectLockQty() != null).map(Inventory::getRejectLockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//            BigDecimal rejectWayQty = inventoryList.stream().filter(c -> c.getRejectWayQty() != null).map(Inventory::getRejectWayQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//            BigDecimal inspectedQty = inventoryList.stream().filter(c -> c.getInspectedQty() != null).map(Inventory::getInspectedQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//            BigDecimal pickingQty = inventoryList.stream().filter(c -> c.getPickingQty() != null).map(Inventory::getPickingQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//
//            switch (model.getFrom().getValue()) {
//                case TargetTypeVo.Normal:
//                    //减去 对应的锁库 残次 的 不能大于当前的库存
//                    BigDecimal qty = stockQty.subtract(lockQty.add(detDefectQty).add(displayQty));
//                    if (qty.compareTo(model.getQty()) < 0) {
//                        // throw new InventoryException(model.getItem().getId(), itemIdName+" 出库数量大于库存数量-锁库数量-残次数量 库存数："+stockQty.subtract(lockQty.add(detDefectQty)));
//                        throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + "  库存不足：" + model.getQty().subtract(qty));
//                    }
//                    break;
//                case TargetTypeVo.Lock:
//                    if (lockQty.compareTo(model.getQty()) < 0) {
//                        throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 锁库库存不足：" + model.getQty().subtract(lockQty));
//                    }
//                    break;
//                case TargetTypeVo.Display:
//                    if (displayQty.compareTo(model.getQty()) < 0) {
//                        throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 展品库存不足：" + model.getQty().subtract(displayQty));
//                    }
//                    break;
//                case TargetTypeVo.Defect:
//                    if (detDefectQty.compareTo(model.getQty()) < 0) {
//                        throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 残次库存不足：" + model.getQty().subtract(detDefectQty));
//                    }
//                    break;
//                case TargetTypeVo.Way:
//                    if (wayQty.compareTo(model.getQty()) < 0) {
//                        throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 在途库存不足：" + model.getQty().subtract(wayQty));
//                    }
//                    break;
//                case TargetTypeVo.Storage:
//                    if (storageQty.compareTo(model.getQty()) < 0) {
//                        throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 暂存库存不足：" + model.getQty().subtract(storageQty));
//                    }
//                    break;
//                case TargetTypeVo.RejectLock:
//                    if (rejectLockQty.compareTo(model.getQty()) < 0) {
//                        throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 次品锁定库存不足：" + model.getQty().subtract(rejectLockQty));
//                    }
//                    break;
//                case TargetTypeVo.RejectWay:
//                    if (rejectWayQty.compareTo(model.getQty()) < 0) {
//                        throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 次品在途库存不足：" + model.getQty().subtract(rejectWayQty));
//                    }
//                    break;
//                case TargetTypeVo.Inspected:
//                    if (inspectedQty.compareTo(model.getQty()) < 0) {
//                        throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 待检库存不足：" + model.getQty().subtract(inspectedQty));
//                    }
//                    break;
//                case TargetTypeVo.Picking:
//                    if (pickingQty.compareTo(model.getQty()) < 0) {
//                        throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 拣货库存不足：" + model.getQty().subtract(pickingQty));
//                    }
//                    break;
//                default:
//                    throw new Exception("出库源类型不明确");
//            }
//        }
//    }
//
//    private List<Inventory> getExchangeInventory(InventoryExchangeVo inventoryStorageVo, List<Inventory> list1) {
//        list1 = list1.stream().filter(s -> s.getItemId().equals(inventoryStorageVo.getItem().getId())).collect(Collectors.toList());
//        if (inventoryStorageVo.getBatchNo() == null) {
//            list1 = list1.stream().filter(s -> s.getBatchNo() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getBatchNo() != null).filter(s -> s.getBatchNo().equals(inventoryStorageVo.getBatchNo())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getFromStockId() == null) {
//            list1 = list1.stream().filter(s -> s.getStockId() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getStockId() != null).filter(s -> s.getStockId().equals(inventoryStorageVo.getFromStockId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getFnSku() == null) {
//            list1 = list1.stream().filter(s -> s.getFnSku() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getFnSku() != null).filter(s -> s.getFnSku().equals(inventoryStorageVo.getFnSku())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getShopId() == null) {
//            list1 = list1.stream().filter(s -> s.getShopId() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getShopId() != null).filter(s -> s.getShopId().equals(inventoryStorageVo.getShopId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getProjectId() == null) {
//            list1 = list1.stream().filter(s -> s.getProjectId() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getProjectId() != null).filter(s -> s.getProjectId().equals(inventoryStorageVo.getProjectId())).collect(Collectors.toList());
//        }
//        return  list1;
//    }
//
//
//    private void exchangeTargetTypeBatchNo(InventoryExchangeVo model, List<InventoryBatchNo> list2, InventoryListReturnVo inventoryListReturnVo) throws Exception {
//        if (model.getFromBinIds() != null || model.getToBinIds() != null) {
//            if(model.getFromBinIds().size() != 0||model.getToBinIds().size() !=0 ){
//                throw new Exception("此操作目前不支持带库位处理!");
//            }
//        }
//        boolean    IsOpenNegativeInventory=   getIsOpenNegativeInventory(model.getFromStockId());
//        List<InventoryBatchNo> inventoryBatchNoList = getExchangeInventoryBatch(model,list2);
//        if(CollectionUtils.isEmpty(inventoryBatchNoList)){
//            if(IsOpenNegativeInventory){
//                throw new Exception(getItemIdName(model.getItem().getId())+"要操作的源库存不存在！");
//            }else {
//                //添加新的 直接根据
//                InventoryBatchNo inventoryStorageVo=new InventoryBatchNo();
//                BeanUtils.copyProperties(model,inventoryStorageVo);
//                storageAgeExchangeInsert(model,inventoryStorageVo,inventoryListReturnVo);
//            }
//        }else {
//            if(IsOpenNegativeInventory) {
//                verificationOexchangeTargetTypeBatchNo(model, inventoryBatchNoList);
//            }
//            BigDecimal qtySum = model.getQty();
//            List<InventoryBatchNo> updateInventoryBatchNoList=new ArrayList<>();
//            for (InventoryBatchNo inventory : inventoryBatchNoList) {
//                //需要处理的数量
//                BigDecimal  num = model.getQty();
//                if (qtySum.compareTo(BigDecimal.ZERO) == 0) {
//                    //库存都处理完
//                    break;
//                }
//                ChangeNum stockQty = new ChangeNum(inventory.getStockQty());
//                ChangeNum lockQty = new ChangeNum(inventory.getLockQty());
//                ChangeNum displayQty = new ChangeNum(inventory.getDisplayQty());
//                ChangeNum defectQty = new ChangeNum(inventory.getDefectQty());
//                ChangeNum wayQty = new ChangeNum(inventory.getWayQty());
//                ChangeNum storageQty = new ChangeNum(inventory.getStorageQty());
//                ChangeNum rejectLockQty = new ChangeNum(inventory.getRejectLockQty());
//                ChangeNum rejectWayQty = new ChangeNum(inventory.getRejectWayQty());
//                ChangeNum inspectedQty = new ChangeNum(inventory.getInspectedQty());
//                ChangeNum pickingQty = new ChangeNum(inventory.getPickingQty());
//                // InventoryListReturnVo inventoryListReturnVo=new InventoryListReturnVo();
//                InventoryVariation inventoryVariation=new InventoryVariation();
//                BeanUtils.copyProperties(model,inventoryVariation);
//                inventoryVariation.setChangeType("Exchange");
//                inventoryVariation.setStockId(model.getFromStockId());
//                inventoryVariation.setFromType(model.getFrom().getValue());
//                inventoryVariation.setToType(model.getTo().getValue());
//                inventoryVariation.setItemId(model.getItem().getId());
//                inventoryVariation.setOperateTime(new Date());
//
//                InventoryBatchNo updateInventory = new InventoryBatchNo();
//                updateInventory.setId(inventory.getId());
//                updateInventory.setVersion(inventory.getVersion());
//                // 处理出
//                switch (model.getFrom().getValue()) {
//                    case TargetTypeVo.Normal:
//                        if(!IsOpenNegativeInventory){
//                            stockQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        }else if (stockQty.getValue().compareTo(qtySum) >= 0) {
//                            num=qtySum;
//                            stockQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num=stockQty.getValue();
//                            qtySum = qtySum.subtract(stockQty.getValue());
//                            stockQty.subtract(stockQty.getValue());
//
//                        }
//                        break;
//                    case TargetTypeVo.Display:
//                        if(!IsOpenNegativeInventory){
//                            stockQty.subtract(model.getQty());
//                            displayQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        }else if (displayQty.getValue().compareTo(qtySum) >= 0) {
//                            num=qtySum;
//                            stockQty.subtract(qtySum);
//                            displayQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num=displayQty.getValue();
//                            qtySum = qtySum.subtract(stockQty.getValue());
//                            stockQty.subtract(stockQty.getValue());
//                            displayQty.subtract(displayQty.getValue());
//                        }
//
//                        break;
//                    case TargetTypeVo.Defect:
//                        if(!IsOpenNegativeInventory){
//                            stockQty.subtract(model.getQty());
//                            defectQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        }else if (defectQty.getValue().compareTo(qtySum) >= 0) {
//                            num=qtySum;
//                            stockQty.subtract(qtySum);
//                            defectQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num=defectQty.getValue();
//                            qtySum = qtySum.subtract(stockQty.getValue());
//                            stockQty.subtract(stockQty.getValue());
//                            defectQty.subtract(defectQty.getValue());
//
//                        }
//                        break;
//                    case TargetTypeVo.Lock:
//                        if(!IsOpenNegativeInventory){
//                            stockQty.subtract(model.getQty());
//                            lockQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        }else if (lockQty.getValue().compareTo(qtySum) >= 0) {
//                            num=qtySum;
//                            stockQty.subtract(qtySum);
//                            lockQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num=lockQty.getValue();
//                            qtySum = qtySum.subtract(stockQty.getValue());
//                            stockQty.subtract(stockQty.getValue());
//                            lockQty.subtract(lockQty.getValue());
//
//                        }
//                        break;
//                    case TargetTypeVo.Way:
//                        if(!IsOpenNegativeInventory){
//                            wayQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        }else if (wayQty.getValue().compareTo(qtySum) >= 0) {
//                            num=qtySum;
//                            wayQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num=wayQty.getValue();
//                            qtySum = qtySum.subtract(wayQty.getValue());
//                            wayQty.subtract(wayQty.getValue());
//
//                        }
//                        break;
//                    case TargetTypeVo.Storage:
//                        if(!IsOpenNegativeInventory){
//                            storageQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        }else if (storageQty.getValue().compareTo(qtySum) >= 0) {
//                            num=qtySum;
//                            storageQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num=storageQty.getValue();
//                            qtySum = qtySum.subtract(storageQty.getValue());
//                            storageQty.subtract(storageQty.getValue());
//
//                        }
//                        break;
//                    case TargetTypeVo.RejectLock:
//                        if(!IsOpenNegativeInventory){
//                            rejectLockQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        }else if (rejectLockQty.getValue().compareTo(qtySum) >= 0) {
//                            num=qtySum;
//                            rejectLockQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num=rejectLockQty.getValue();
//                            qtySum = qtySum.subtract(rejectLockQty.getValue());
//                            rejectLockQty.subtract(rejectLockQty.getValue());
//
//                        }
//                        // storageQty.subtract(model.getQty());
//                        break;
//                    case TargetTypeVo.RejectWay:
//                        if(!IsOpenNegativeInventory){
//                            rejectWayQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        }else if (rejectWayQty.getValue().compareTo(qtySum) >= 0) {
//                            num=qtySum;
//                            rejectWayQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num=rejectWayQty.getValue();
//                            qtySum = qtySum.subtract(rejectWayQty.getValue());
//                            rejectWayQty.subtract(rejectWayQty.getValue());
//
//                        }
//                        break;
//                    case TargetTypeVo.Inspected:
//                        if(!IsOpenNegativeInventory){
//                            inspectedQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        }else if (inspectedQty.getValue().compareTo(qtySum) >= 0) {
//                            num=qtySum;
//                            inspectedQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num=inspectedQty.getValue();
//                            qtySum = qtySum.subtract(inspectedQty.getValue());
//                            inspectedQty.subtract(inspectedQty.getValue());
//                        }
//                        break;
//                    case TargetTypeVo.Picking:
//                        if(!IsOpenNegativeInventory){
//                            pickingQty.subtract(model.getQty());
//                            qtySum = BigDecimal.ZERO;
//                        }else if (pickingQty.getValue().compareTo(qtySum) >= 0) {
//                            num=qtySum;
//                            pickingQty.subtract(qtySum);
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            num=pickingQty.getValue();
//                            qtySum = qtySum.subtract(pickingQty.getValue());
//                            pickingQty.subtract(pickingQty.getValue());
//
//                        }
//                        break;
//                }
//
//                // 处理入
//                switch (model.getTo().getValue()) {
//                    case TargetTypeVo.Normal:
//                        stockQty.add(num);
//                        break;
//                    case TargetTypeVo.Display:
//                        stockQty.add(num);
//                        displayQty.add(num);
//                        break;
//                    case TargetTypeVo.Defect:
//                        stockQty.add(num);
//                        defectQty.add(num);
//                        break;
//                    case TargetTypeVo.Lock:
//                        stockQty.add(num);
//                        lockQty.add(num);
//                        break;
//                    case TargetTypeVo.Way:
//                        wayQty.add(num);
//                        break;
//                    case TargetTypeVo.Storage:
//                        storageQty.add(num);
//                        break;
//                    case TargetTypeVo.RejectLock:
//                        rejectLockQty.add(num);
//                        break;
//                    case TargetTypeVo.RejectWay:
//                        rejectWayQty.add(num);
//                        break;
//                    case TargetTypeVo.Inspected:
//                        inspectedQty.add(num);
//                        break;
//                    case TargetTypeVo.Picking:
//                        pickingQty.add(num);
//                        break;
//                }
//
//                updateInventory.setStockQty(stockQty.getValue());
//                inventoryVariation.setStockQty(stockQty.getValue());
//                inventoryVariation.setChangeStockQty(stockQty.getChange());
//                updateInventory.setLockQty(lockQty.getValue());
//                inventoryVariation.setLockQty(lockQty.getValue());
//                inventoryVariation.setChangeLockQty(lockQty.getChange());
//                updateInventory.setWayQty(wayQty.getValue());
//                inventoryVariation.setWayQty(wayQty.getValue());
//                inventoryVariation.setChangeWayQty(wayQty.getChange());
//                updateInventory.setDisplayQty(displayQty.getValue());
//                inventoryVariation.setDisplayQty(displayQty.getValue());
//                inventoryVariation.setChangeDisplayQty(displayQty.getChange());
//                updateInventory.setDefectQty(defectQty.getValue());
//                inventoryVariation.setDefectQty(defectQty.getValue());
//                inventoryVariation.setChangeDefectQty(defectQty.getChange());
//                updateInventory.setStorageQty(storageQty.getValue());
//                inventoryVariation.setStorageQty(storageQty.getValue());
//                inventoryVariation.setChangeStorageQty(storageQty.getChange());
//                updateInventory.setRejectLockQty(rejectLockQty.getValue());
//                inventoryVariation.setRejectLockQty(rejectLockQty.getValue());
//                inventoryVariation.setChangeRejectLockQty(rejectLockQty.getChange());
//                updateInventory.setRejectWayQty(rejectWayQty.getValue());
//                inventoryVariation.setRejectWayQty(rejectWayQty.getValue());
//                inventoryVariation.setChangeRejectWayQty(rejectWayQty.getChange());
//                updateInventory.setInspectedQty(inspectedQty.getValue());
//                inventoryVariation.setInspectedQty(inspectedQty.getValue());
//                inventoryVariation.setChangeInspectedQty(inspectedQty.getChange());
//                updateInventory.setPickingQty(pickingQty.getValue());
//                inventoryVariation.setPickingQty(pickingQty.getValue());
//                inventoryVariation.setChangePickingQty(pickingQty.getChange());
//                updateInventoryBatchNoList.add(updateInventory);
//            }
//            inventoryListReturnVo.setUpdateInventoryBatchNoList(updateInventoryBatchNoList);
//        }
//    }
//
//    private void storageAgeExchangeInsert(InventoryExchangeVo model, InventoryBatchNo inventoryBatchNo, InventoryListReturnVo inventoryListReturnVo) {
//        inventoryBatchNo.setStockId(model.getFromStockId());
//        inventoryBatchNo.setItemId(model.getItem().getId());
//        if (StringUtils.isBlank(model.getBatchNo())) {
//            inventoryBatchNo.setBatchNo(null);
//        }
//        inventoryBatchNo.setStockQty(BigDecimal.ZERO);
//
//        // 处理出
//        switch (model.getFrom().getValue()) {
//            case TargetTypeVo.Normal:
//                inventoryBatchNo.setStockQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.Display:
//                inventoryBatchNo.setDisplayQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.Defect:
//                inventoryBatchNo.setDefectQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.Lock:
//                inventoryBatchNo.setLockQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.Way:
//                inventoryBatchNo.setWayQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.Storage:
//                inventoryBatchNo.setStorageQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.RejectLock:
//                inventoryBatchNo.setRejectLockQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.RejectWay:
//                inventoryBatchNo.setRejectWayQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.Inspected:
//                inventoryBatchNo.setInspectedQty(model.getQty().negate());
//                break;
//            case TargetTypeVo.Picking:
//                inventoryBatchNo.setPickingQty(model.getQty().negate());
//                break;
//        }
//
//        // 处理入
//        switch (model.getTo().getValue()) {
//            case TargetTypeVo.Normal:
//                inventoryBatchNo.setStockQty(model.getQty());
//                break;
//            case TargetTypeVo.Display:
//                inventoryBatchNo.setDisplayQty(model.getQty());
//
//                break;
//            case TargetTypeVo.Defect:
//                inventoryBatchNo.setDefectQty(model.getQty());
//
//                break;
//            case TargetTypeVo.Lock:
//                inventoryBatchNo.setLockQty(model.getQty());
//
//                break;
//            case TargetTypeVo.Way:
//                inventoryBatchNo.setWayQty(model.getQty());
//                break;
//            case TargetTypeVo.Storage:
//                inventoryBatchNo.setStorageQty(model.getQty());
//                break;
//            case TargetTypeVo.RejectLock:
//                inventoryBatchNo.setRejectLockQty(model.getQty());
//                break;
//            case TargetTypeVo.RejectWay:
//                inventoryBatchNo.setRejectWayQty(model.getQty());
//                break;
//            case TargetTypeVo.Inspected:
//                inventoryBatchNo.setInspectedQty(model.getQty());
//                break;
//            case TargetTypeVo.Picking:
//                inventoryBatchNo.setPickingQty(model.getQty());
//                break;
//        }
//
//        inventoryListReturnVo.setInventoryBatchNo(inventoryBatchNo);
//
//    }
//
//    private void verificationOexchangeTargetTypeBatchNo(InventoryExchangeVo model, List<InventoryBatchNo> inventoryBatchNoList) throws Exception
//
//    {
//        //校验库存是否有那么多
//        BigDecimal stockQty = inventoryBatchNoList.stream().filter(c -> c.getStockQty() != null).map(InventoryBatchNo::getStockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal lockQty = inventoryBatchNoList.stream().filter(c -> c.getLockQty() != null).map(InventoryBatchNo::getLockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal detDefectQty = inventoryBatchNoList.stream().filter(c -> c.getDefectQty() != null).map(InventoryBatchNo::getDefectQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal displayQty = inventoryBatchNoList.stream().filter(c -> c.getDisplayQty() != null).map(InventoryBatchNo::getDisplayQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal wayQty = inventoryBatchNoList.stream().filter(c -> c.getWayQty() != null).map(InventoryBatchNo::getWayQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal storageQty = inventoryBatchNoList.stream().filter(c -> c.getStorageQty() != null).map(InventoryBatchNo::getStorageQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal rejectLockQty = inventoryBatchNoList.stream().filter(c -> c.getRejectLockQty() != null).map(InventoryBatchNo::getRejectLockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal rejectWayQty = inventoryBatchNoList.stream().filter(c -> c.getRejectWayQty() != null).map(InventoryBatchNo::getRejectWayQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal inspectedQty = inventoryBatchNoList.stream().filter(c -> c.getInspectedQty() != null).map(InventoryBatchNo::getInspectedQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal pickingQty = inventoryBatchNoList.stream().filter(c -> c.getPickingQty() != null).map(InventoryBatchNo::getPickingQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//
//        switch (model.getFrom().getValue()) {
//            case TargetTypeVo.Normal:
//                //减去 对应的锁库 残次 的 不能大于当前的库存
//                BigDecimal qty = stockQty.subtract(lockQty.add(detDefectQty).add(displayQty));
//                if (qty.compareTo(model.getQty()) < 0) {
//                    // throw new InventoryException(model.getItem().getId(), itemIdName+" 出库数量大于库存数量-锁库数量-残次数量 库存数："+stockQty.subtract(lockQty.add(detDefectQty)));
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + "  库存不足：" + model.getQty().subtract(qty));
//                }
//                break;
//            case TargetTypeVo.Lock:
//                if (lockQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 锁库库存不足：" + model.getQty().subtract(lockQty));
//                }
//                break;
//            case TargetTypeVo.Display:
//                if (displayQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 展品库存不足：" + model.getQty().subtract(displayQty));
//                }
//                break;
//            case TargetTypeVo.Defect:
//                if (detDefectQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 残次库存不足：" + model.getQty().subtract(detDefectQty));
//                }
//                break;
//            case TargetTypeVo.Way:
//                if (wayQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 在途库存不足：" + model.getQty().subtract(wayQty));
//                }
//                break;
//            case TargetTypeVo.Storage:
//                if (storageQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 暂存库存不足：" + model.getQty().subtract(storageQty));
//                }
//                break;
//            case TargetTypeVo.RejectLock:
//                if (rejectLockQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 次品锁定库存不足：" + model.getQty().subtract(rejectLockQty));
//                }
//                break;
//            case TargetTypeVo.RejectWay:
//                if (rejectWayQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 次品在途库存不足：" + model.getQty().subtract(rejectWayQty));
//                }
//                break;
//            case TargetTypeVo.Inspected:
//                if (inspectedQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 待检库存不足：" + model.getQty().subtract(inspectedQty));
//                }
//                break;
//            case TargetTypeVo.Picking:
//                if (pickingQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 拣货库存不足：" + model.getQty().subtract(pickingQty));
//                }
//                break;
//            default:
//                throw new Exception("出库源类型不明确");
//        }
//    }
//
//    private List<InventoryBatchNo> getExchangeInventoryBatch(InventoryExchangeVo inventoryStorageVo, List<InventoryBatchNo> list1) {
//        list1 = list1.stream().filter(s -> s.getItemId().equals(inventoryStorageVo.getItem().getId())).collect(Collectors.toList());
//        if (inventoryStorageVo.getBatchNo() == null) {
//            list1 = list1.stream().filter(s -> s.getBatchNo() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getBatchNo() != null).filter(s -> s.getBatchNo().equals(inventoryStorageVo.getBatchNo())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getFromStockId() == null) {
//            list1 = list1.stream().filter(s -> s.getStockId() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getStockId() != null).filter(s -> s.getStockId().equals(inventoryStorageVo.getFromStockId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getFnSku() == null) {
//            list1 = list1.stream().filter(s -> s.getFnSku() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getFnSku() != null).filter(s -> s.getFnSku().equals(inventoryStorageVo.getFnSku())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getShopId() == null) {
//            list1 = list1.stream().filter(s -> s.getShopId() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getShopId() != null).filter(s -> s.getShopId().equals(inventoryStorageVo.getShopId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getProjectId() == null) {
//            list1 = list1.stream().filter(s -> s.getProjectId() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getProjectId() != null).filter(s -> s.getProjectId().equals(inventoryStorageVo.getProjectId())).collect(Collectors.toList());
//        }
//        return  list1;
//    }
//
//    private InventoryListReturnVo exchangeShift(InventoryExchangeVo model, List<BinIdsVo> fromBinIdsVos, List<BinIdsVo> toBinIdsVos, List<InventoryPlacement> list1)  throws Exception{
//        InventoryListReturnVo inventoryListReturnVo=new InventoryListReturnVo();
//        InventoryVariation inventoryVariation=new InventoryVariation();
//        BeanUtils.copyProperties(model,inventoryVariation);
//        inventoryVariation.setChangeType("Exchange");
//        inventoryVariation.setStockId(model.getFromStockId());
//        inventoryVariation.setFromType(model.getFrom().getValue());
//        inventoryVariation.setToType(model.getTo().getValue());
//        inventoryVariation.setItemId(model.getItem().getId());
//        inventoryVariation.setOperateTime(new Date());
//
//        List<InventoryPlacement> insertInventoryPlacementList=new ArrayList<>();
//        List<InventoryPlacement> updateInventoryPlacementList=new ArrayList<>();
//        List<InventoryPlacementVariation> insertIInventoryPlacementVariationList=new ArrayList<>();
//
//        //查询对应的仓库 -库存  如果数量不足  提示报错
//        for (BinIdsVo binIdsVo: fromBinIdsVos){
//            InventoryPlacementVariation inventoryPlacementVariation=new InventoryPlacementVariation();
//            BeanUtils.copyProperties(model,inventoryVariation);
//            inventoryPlacementVariation.setChangeType("Exchange");
//            inventoryPlacementVariation.setStockId(model.getFromStockId());
//            inventoryPlacementVariation.setFromType(model.getFromBinIdsType().getValue());
//            inventoryPlacementVariation.setToType(model.getToBinIdsType().getValue());
//            inventoryPlacementVariation.setItemId(model.getItem().getId());
//            inventoryPlacementVariation.setOperateTime(new Date());
//            inventoryPlacementVariation.setBinId(binIdsVo.getBinId());
//            inventoryPlacementVariation.setShopId(model.getShopId());
//            inventoryPlacementVariation.setFormNum(model.getFormNum());
//            inventoryPlacementVariation.setFormOperator(model.getFormOperator());
//            inventoryPlacementVariation.setOperateKey(model.getOperateKey());
//            inventoryPlacementVariation.setFnSku(model.getFnSku());
//            inventoryPlacementVariation.setDocumentType(model.getDocumentType());
//            List<InventoryPlacement> inventoryPlacementList= getExchangeInventoryPlacementList(model,binIdsVo.getBinId(),list1,1);
//            if (CollectionUtils.isEmpty(inventoryPlacementList)) {
//                if(getIsOpenNegativeInventory(model.getFromStockId())){
//                    throw new Exception(getItemIdName(model.getItem().getId())+ "没有对应库位内码");
//                }else {
//                    //新增负数
//                    InventoryPlacement insertInventoryPlacement=new InventoryPlacement();
//                    BeanUtils.copyProperties(model,insertInventoryPlacement);
//                    insertInventoryPlacement.setStockId(model.getFromStockId());
//                    insertInventoryPlacement.setBinId(binIdsVo.getBinId());
//                    insertInventoryPlacement.setItemId(model.getItem().getId());
//                    if(StringUtils.isBlank(model.getBatchNo())){
//                        insertInventoryPlacement.setBatchNo(null);
//                    }
//                    switch (model.getFromBinIdsType().getValue()) {
//                        case TargetTypeVo.Normal:
//                            insertInventoryPlacement.setStockQty(new BigDecimal(binIdsVo.getQty()).negate());
//                            inventoryPlacementVariation.setStockQty(new BigDecimal(binIdsVo.getQty()).negate());
//                            inventoryPlacementVariation.setChangeStockQty(new BigDecimal(binIdsVo.getQty()).negate());
//                            break;
//                        case TargetTypeVo.Lock:
//                            insertInventoryPlacement.setLockQty(new BigDecimal(binIdsVo.getQty()).negate());
//                            inventoryPlacementVariation.setLockQty(new BigDecimal(binIdsVo.getQty()).negate());
//                            inventoryPlacementVariation.setChangeLockQty(new BigDecimal(binIdsVo.getQty()).negate());
//                            break;
//                        case TargetTypeVo.Way:
//                            insertInventoryPlacement.setWayQty(new BigDecimal(binIdsVo.getQty()).negate());
//                            inventoryPlacementVariation.setWayQty(new BigDecimal(binIdsVo.getQty()).negate());
//                            inventoryPlacementVariation.setChangeWayQty(new BigDecimal(binIdsVo.getQty()).negate());
//                            break;
//                        default:
//                            throw new Exception("出库位类型不明确");
//                    }
//                    insertInventoryPlacementList.add(insertInventoryPlacement);
//                    insertIInventoryPlacementVariationList.add(inventoryPlacementVariation);
//                }
//            }else {
//                BigDecimal stockQtySum= inventoryPlacementList.stream().filter(c -> c.getStockQty() != null).map(InventoryPlacement::getStockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//                BigDecimal lockQtySum= inventoryPlacementList.stream().filter(c -> c.getLockQty() != null).map(InventoryPlacement::getLockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//                BigDecimal wayQtySum= inventoryPlacementList.stream().filter(c -> c.getWayQty() != null).map(InventoryPlacement::getWayQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//                //如果开启负库存  不在校验库位数量
//                if(getIsOpenNegativeInventory(model.getFromStockId())){
//                    switch (model.getFromBinIdsType().getValue()) {
//                        case TargetTypeVo.Normal:
//                            if(stockQtySum.compareTo(new BigDecimal(binIdsVo.getQty()))==-1){
//                                throw new Exception(getItemIdName(model.getItem().getId())+"库存货位放置表正常库存不足");
//                            }
//                            inventoryPlacementVariation.setStockQty(stockQtySum.subtract(new BigDecimal(binIdsVo.getQty())));
//                            inventoryPlacementVariation.setChangeStockQty(new BigDecimal(binIdsVo.getQty()).negate());
//                            break;
//                        case TargetTypeVo.Lock:
//                            if(lockQtySum.compareTo(new BigDecimal(binIdsVo.getQty()))==-1){
//                                throw new Exception(getItemIdName(model.getItem().getId())+"库存货位放置表锁定库存不足");
//                            }
//                            inventoryPlacementVariation.setLockQty(lockQtySum.subtract(new BigDecimal(binIdsVo.getQty())));
//                            inventoryPlacementVariation.setChangeLockQty(new BigDecimal(binIdsVo.getQty()).negate());
//                            break;
//                        case TargetTypeVo.Way:
//                            if(wayQtySum.compareTo(new BigDecimal(binIdsVo.getQty()))==-1){
//                                throw new Exception(getItemIdName(model.getItem().getId())+"库存货位放置表在途库存不足");
//                            }
//                            inventoryPlacementVariation.setWayQty(wayQtySum.subtract(new BigDecimal(binIdsVo.getQty())));
//                            inventoryPlacementVariation.setChangeWayQty(new BigDecimal(binIdsVo.getQty()).negate());
//                            break;
//                        default:
//                            throw new Exception("出库位类型不明确");
//                    }
//                }else {
//                    switch (model.getFromBinIdsType().getValue()) {
//                        case TargetTypeVo.Normal:
//                            inventoryPlacementVariation.setStockQty(stockQtySum.subtract(new BigDecimal(binIdsVo.getQty())));
//                            inventoryPlacementVariation.setChangeStockQty(new BigDecimal(binIdsVo.getQty()));
//                            break;
//                        case TargetTypeVo.Lock:
//                            inventoryPlacementVariation.setLockQty(lockQtySum.subtract(new BigDecimal(binIdsVo.getQty())));
//                            inventoryPlacementVariation.setChangeLockQty(new BigDecimal(binIdsVo.getQty()));
//                            break;
//                        case TargetTypeVo.Way:
//                            inventoryPlacementVariation.setWayQty(wayQtySum.subtract(new BigDecimal(binIdsVo.getQty())));
//                            inventoryPlacementVariation.setChangeWayQty(new BigDecimal(binIdsVo.getQty()));
//                            break;
//                        default:
//                            throw new Exception("出库位类型不明确");
//                    }
//                }
//                insertIInventoryPlacementVariationList.add(inventoryPlacementVariation);
//                BigDecimal qtySum= new BigDecimal(binIdsVo.getQty());
//                for (InventoryPlacement inventoryPlacement : inventoryPlacementList) {
//                    InventoryPlacement updateInventoryPlacement=new InventoryPlacement();
//                    updateInventoryPlacement.setId(inventoryPlacement.getId());
//                    updateInventoryPlacement.setVersion(inventoryPlacement.getVersion());
//                    switch (model.getFromBinIdsType().getValue()) {
//                        case TargetTypeVo.Normal:
//                            if(inventoryPlacement.getStockQty()==null){
//                                inventoryPlacement.setStockQty(new BigDecimal(0));
//                            }
//                            if(qtySum.compareTo(BigDecimal.ZERO)==0){
//                                break;
//                            }else if(!getIsOpenNegativeInventory(model.getFromStockId())){
//                                updateInventoryPlacement.setStockQty(inventoryPlacement.getStockQty().subtract(qtySum));
//                                qtySum=BigDecimal.ZERO;
//                            }else if(qtySum.compareTo(inventoryPlacement.getStockQty())>=0){
//                                qtySum=qtySum.subtract(inventoryPlacement.getStockQty());
//                                updateInventoryPlacement.setStockQty(BigDecimal.ZERO);
//                            }else if (qtySum.compareTo(inventoryPlacement.getStockQty())==-1){
//                                updateInventoryPlacement.setStockQty(inventoryPlacement.getStockQty().subtract(qtySum));
//                                qtySum=BigDecimal.ZERO;
//                            }
//                            break;
//                        case TargetTypeVo.Lock:
//                            if(inventoryPlacement.getLockQty()==null){
//                                inventoryPlacement.setLockQty(new BigDecimal(0));
//                            }
//                            if(qtySum.compareTo(BigDecimal.ZERO)==0){
//                                break;
//                            }else if(!getIsOpenNegativeInventory(model.getFromStockId())){
//                                updateInventoryPlacement.setLockQty(inventoryPlacement.getLockQty().subtract(qtySum));
//                                qtySum=BigDecimal.ZERO;
//                            }else if(qtySum.compareTo(inventoryPlacement.getLockQty())>=0){
//                                qtySum=qtySum.subtract(inventoryPlacement.getLockQty());
//                                updateInventoryPlacement.setLockQty( BigDecimal.ZERO);
//                            }else if (qtySum.compareTo(inventoryPlacement.getLockQty())==-1){
//                                updateInventoryPlacement.setLockQty(inventoryPlacement.getLockQty().subtract(qtySum));
//                                qtySum=BigDecimal.ZERO;
//                            }
//                            break;
//                        case TargetTypeVo.Way:
//                            if(inventoryPlacement.getWayQty()==null){
//                                inventoryPlacement.setWayQty(new BigDecimal(0));
//                            }
//                            if(qtySum.compareTo(BigDecimal.ZERO)==0){
//                                break;
//                            }else if(!getIsOpenNegativeInventory(model.getFromStockId())){
//                                updateInventoryPlacement.setWayQty(inventoryPlacement.getWayQty().subtract(qtySum));
//
//                                qtySum=BigDecimal.ZERO;
//                            }else if(qtySum.compareTo(inventoryPlacement.getWayQty())>=0){
//                                qtySum=qtySum.subtract(inventoryPlacement.getWayQty());
//                                updateInventoryPlacement.setWayQty(BigDecimal.ZERO);
//                            }else if (qtySum.compareTo(inventoryPlacement.getWayQty())==-1){
//                                updateInventoryPlacement.setWayQty(inventoryPlacement.getWayQty().subtract(qtySum));
//                                qtySum=BigDecimal.ZERO;
//                            }
//
//                            break;
//                        default:
//                            throw new Exception("出库位类型不明确");
//                    }
//                    updateInventoryPlacementList.add(updateInventoryPlacement);
//                }
//            }
//        }
//        //查询对应的仓库 -库存  如果没有 添加 有自动添加数量
//        for (BinIdsVo binIdsVo: toBinIdsVos){
//            InventoryPlacementVariation inventoryPlacementVariation=new InventoryPlacementVariation();
//            BeanUtils.copyProperties(model,inventoryVariation);
//            inventoryPlacementVariation.setChangeType("Exchange");
//            inventoryPlacementVariation.setStockId(model.getFromStockId());
//            inventoryPlacementVariation.setFromType(model.getFromBinIdsType().getValue());
//            inventoryPlacementVariation.setToType(model.getToBinIdsType().getValue());
//            inventoryPlacementVariation.setItemId(model.getItem().getId());
//            inventoryPlacementVariation.setOperateTime(new Date());
//            inventoryPlacementVariation.setBinId(binIdsVo.getBinId());
//            inventoryPlacementVariation.setShopId(model.getShopId());
//            inventoryPlacementVariation.setFormNum(model.getFormNum());
//            inventoryPlacementVariation.setFormOperator(model.getFormOperator());
//            inventoryPlacementVariation.setOperateKey(model.getOperateKey());
//            inventoryPlacementVariation.setFnSku(model.getFnSku());
//            inventoryPlacementVariation.setDocumentType(model.getDocumentType());
//            List<InventoryPlacement> inventoryPlacementList= getExchangeInventoryPlacementList(model,binIdsVo.getBinId(),list1,2);
//            InventoryPlacement inventoryPlacement=new InventoryPlacement();
//            if (CollectionUtils.isNotEmpty(inventoryPlacementList)){
//                inventoryPlacement=inventoryPlacementList.get(0);
//            }else {
//                inventoryPlacement= null;
//            }
//            if(inventoryPlacement!=null){
//                //修改同一个id问题
//                InventoryPlacement updateInventoryPlacement=new InventoryPlacement();
//                if(updateInventoryPlacementList.size()>0){
//                    List<InventoryPlacement> NewList=updateInventoryPlacementList.stream().filter(s->s.getId().equals(inventoryPlacementList.get(0).getId())).collect(Collectors.toList());
//                    if(CollectionUtils.isNotEmpty(NewList)){
//                        updateInventoryPlacementList=updateInventoryPlacementList.stream().filter(s->!s.getId().equals(inventoryPlacementList.get(0).getId())).collect(Collectors.toList());
//                        updateInventoryPlacement=NewList.get(0);
//                    }else {
//                        updateInventoryPlacement.setId(inventoryPlacement.getId());
//                        updateInventoryPlacement.setVersion(inventoryPlacement.getVersion()) ;
//                    }
//                }
//
//                switch (model.getToBinIdsType().getValue()) {
//                    case TargetTypeVo.Normal:
//                        if(inventoryPlacement.getStockQty()==null){
//                            inventoryPlacement.setStockQty(new BigDecimal(0));
//                        }
//                        inventoryPlacementVariation.setStockQty( inventoryPlacement.getStockQty().add(new BigDecimal(binIdsVo.getQty())));
//                        inventoryPlacementVariation.setChangeStockQty(new BigDecimal(binIdsVo.getQty()));
//                        updateInventoryPlacement.setStockQty(inventoryPlacement.getStockQty().add(new BigDecimal(binIdsVo.getQty())));
//
//                        break;
//                    case TargetTypeVo.Lock:
//                        if(inventoryPlacement.getLockQty()==null){
//                            inventoryPlacement.setLockQty(new BigDecimal(0));
//                        }
//                        inventoryPlacementVariation.setLockQty( inventoryPlacement.getLockQty().add(new BigDecimal(binIdsVo.getQty())));
//                        inventoryPlacementVariation.setChangeLockQty(new BigDecimal(binIdsVo.getQty()));
//                        updateInventoryPlacement.setLockQty(inventoryPlacement.getLockQty().add(new BigDecimal(binIdsVo.getQty())));
//                        break;
//                    case TargetTypeVo.Way:
//                        if(inventoryPlacement.getWayQty()==null){
//                            inventoryPlacement.setWayQty(new BigDecimal(0));
//                        }
//                        inventoryPlacementVariation.setWayQty(inventoryPlacement.getWayQty().add(new BigDecimal(binIdsVo.getQty())));
//                        inventoryPlacementVariation.setChangeWayQty(new BigDecimal(binIdsVo.getQty()));
//                        updateInventoryPlacement.setWayQty(inventoryPlacement.getWayQty().add(new BigDecimal(binIdsVo.getQty())));
//                        break;
//                    default:
//                        throw new Exception("入库位类型不明确");
//                }
//                insertIInventoryPlacementVariationList.add(inventoryPlacementVariation);
//                updateInventoryPlacementList.add(updateInventoryPlacement);
//            }else {
//                //新增
//                InventoryPlacement insertInventoryPlacement=new InventoryPlacement();
//                BeanUtils.copyProperties(model,insertInventoryPlacement);
//                insertInventoryPlacement.setStockId(model.getFromStockId());
//                insertInventoryPlacement.setBinId(binIdsVo.getBinId());
//                switch (model.getToBinIdsType().getValue()) {
//                    case TargetTypeVo.Normal:
//                        insertInventoryPlacement.setStockQty(new BigDecimal(binIdsVo.getQty()));
//                        inventoryPlacementVariation.setStockQty(new BigDecimal(binIdsVo.getQty()));
//                        inventoryPlacementVariation.setChangeStockQty(new BigDecimal(binIdsVo.getQty()));
//                        break;
//                    case TargetTypeVo.Lock:
//                        insertInventoryPlacement.setLockQty(new BigDecimal(binIdsVo.getQty()));
//                        inventoryPlacementVariation.setLockQty(new BigDecimal(binIdsVo.getQty()));
//                        inventoryPlacementVariation.setChangeLockQty(new BigDecimal(binIdsVo.getQty()));
//                        break;
//                    case TargetTypeVo.Way:
//                        inventoryPlacementVariation.setWayQty(new BigDecimal(binIdsVo.getQty()));
//                        inventoryPlacementVariation.setChangeWayQty(new BigDecimal(binIdsVo.getQty()));
//                        insertInventoryPlacement.setWayQty(new BigDecimal(binIdsVo.getQty()));
//                        break;
//                    default:
//                        throw new Exception("入库位类型不明确");
//                }
////                if(inventory!=null){
////                    insertInventoryPlacement.setAuxId(inventory.getAuxId());
////                    insertInventoryPlacement.setAuxQty(inventory.getAuxQty());
////                    insertInventoryPlacement.setProductionDate(inventory.getProductionDate());
////                    insertInventoryPlacement.setExpiryDate(inventory.getExpiryDate());
////                    insertInventoryPlacement.setShelfLife(inventory.getShelfLife());
////                }
//                insertInventoryPlacement.setItemId(model.getItem().getId());
//                if(StringUtils.isBlank(model.getBatchNo())){
//                    insertInventoryPlacement.setBatchNo(null);
//                }
//                insertIInventoryPlacementVariationList.add(inventoryPlacementVariation);
//                insertInventoryPlacementList.add(insertInventoryPlacement);
//            }
//        }
//        inventoryListReturnVo.setInventoryPlacementVariations(insertIInventoryPlacementVariationList);
//        inventoryListReturnVo.setUpdateInventoryPlacementList(updateInventoryPlacementList);
//        inventoryListReturnVo.setInventoryPlacement(insertInventoryPlacementList);
//        return  inventoryListReturnVo;
//    }
//
//    private List<InventoryPlacement> getExchangeInventoryPlacementList(InventoryExchangeVo inventoryStorageVo, Long binId, List<InventoryPlacement> list1, int i) {
//        list1 = list1.stream().filter(s -> s.getItemId().equals(inventoryStorageVo.getItem().getId()) && s.getBinId().equals(binId)).collect(Collectors.toList());
//        if (inventoryStorageVo.getBatchNo() == null) {
//            list1 = list1.stream().filter(s -> s.getBatchNo() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getBatchNo() != null).filter(s -> s.getBatchNo().equals(inventoryStorageVo.getBatchNo())).collect(Collectors.toList());
//        }
//        if(i==1){
//            if (inventoryStorageVo.getFromStockId() == null) {
//                list1 = list1.stream().filter(s -> s.getStockId() == null).collect(Collectors.toList());
//            } else {
//                list1 = list1.stream().filter(s -> s.getStockId() != null).filter(s -> s.getStockId().equals(inventoryStorageVo.getFromStockId())).collect(Collectors.toList());
//            }
//        }else {
//            if (inventoryStorageVo.getToStockId() == null) {
//                list1 = list1.stream().filter(s -> s.getStockId() == null).collect(Collectors.toList());
//            } else {
//                list1 = list1.stream().filter(s -> s.getStockId() != null).filter(s -> s.getStockId().equals(inventoryStorageVo.getToStockId())).collect(Collectors.toList());
//            }
//        }
//
//        if (inventoryStorageVo.getFnSku() == null) {
//            list1 = list1.stream().filter(s -> s.getFnSku() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getFnSku() != null).filter(s -> s.getFnSku().equals(inventoryStorageVo.getFnSku())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getShopId() == null) {
//            list1 = list1.stream().filter(s -> s.getShopId() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getShopId() != null).filter(s -> s.getShopId().equals(inventoryStorageVo.getShopId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getProjectId() == null) {
//            list1 = list1.stream().filter(s -> s.getProjectId() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getProjectId() != null).filter(s -> s.getProjectId().equals(inventoryStorageVo.getProjectId())).collect(Collectors.toList());
//        }
//        return  list1;
//    }
//
//    private Long getExchangeFilterWarehouseBinList(List<WarehouseBin> zWarehouseBinList, InventoryExchangeVo inventoryStorageVo,int type)  throws Exception{
//        if(type==1){
//            zWarehouseBinList = zWarehouseBinList.stream().filter(s -> s.getWarehouseId().equals(inventoryStorageVo.getFromStockId())).collect(Collectors.toList());
//        }else {
//            zWarehouseBinList = zWarehouseBinList.stream().filter(s -> s.getWarehouseId().equals(inventoryStorageVo.getToStockId())).collect(Collectors.toList());
//        }
//        if (CollectionUtils.isEmpty(zWarehouseBinList)) {
//            throw new Exception("没有查到对应仓位");
//        }
//        return zWarehouseBinList.get(0).getId();
//    }
//    private List<WarehouseBinProducts> getExchangeFilterWarehouseProductsBinList(List<WarehouseBinProducts> list, InventoryExchangeVo inventoryStorageVo) {
//        list.stream().filter(s -> s.getProductId().equals(inventoryStorageVo.getItem().getId()));
//        if (ObjectUtils.isEmpty(inventoryStorageVo.getShopId())) {
//            list = list.stream().filter(s -> s.getShopId() == null).collect(Collectors.toList());
//        } else {
//            list = list.stream().filter(s -> s.getShopId() != null).filter(s -> s.getShopId().equals(inventoryStorageVo.getShopId())).collect(Collectors.toList());
//        }
//
//        if (ObjectUtils.isEmpty(inventoryStorageVo.getFnSku())) {
//            list = list.stream().filter(s -> s.getFnsku() == null).collect(Collectors.toList());
//        } else {
//            list = list.stream().filter(s -> s.getShopId() != null).filter(s -> s.getFnsku().equals(inventoryStorageVo.getFnSku())).collect(Collectors.toList());
//        }
//
//        return list;
//    }
//    private void verificationExchange(InventoryExchangeVo model) throws Exception{
//        if (null==model.getFromStockId()){
//            throw new Exception("fromStockId 为空");
//        }
//        if (null==model.getToStockId()){
//            throw new Exception("toStockId 为空");
//        }
//        if (ObjectUtils.allNull(model.getItem())){
//            throw new Exception("item 为空");
//        }
//        if(QtyIsZeroConfig.isOpen){
//            if (model.getQty() == null){
//                throw new Exception("操作数量不能为空");
//            }
//        }else  if (model.getQty() == null || BigDecimal.ZERO.equals(model.getQty())) {
//            throw new Exception("操作数量不能为空或零");
//        }
//        if (!Boolean.TRUE.equals(model.getSupportNegative()) && model.getQty().compareTo(BigDecimal.ZERO)<0) {
//            throw new Exception("操作数量不能为负数");
//        }
//    }
//
//
//
//    private InventoryOutboundVo outNumMergeInventoryStorageVo(List<InventoryOutboundVo> valueList) {
//        InventoryOutboundVo inventoryStorageVo = valueList.get(0);
//        BigDecimal sumQty = valueList.stream().map(InventoryOutboundVo::getQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        inventoryStorageVo.setQty(sumQty);
//        Map<String, List<InventoryOutboundVo>> listMap = valueList
//                .stream()
//                .collect(Collectors.groupingBy(item -> this.outInventoryBinIdsGroupingBy(item)
//                ));
//        Map<Long, Integer> binIds = new HashMap<>();
//        listMap.forEach((key, itemList) -> {
//            if (!ObjectUtils.isEmpty(key)) {
//                if (itemList.size() == 1) {
//                    binIds.putAll(itemList.get(0).getBinIds());
//                } else {
//                    Integer sum = 0;
//                    for (InventoryOutboundVo storageVo : itemList) {
//                        Map<Long, Integer> binIds1 = storageVo.getBinIds();
//                        for (Long key1 : binIds1.keySet()) {
//                            sum = sum + binIds1.get(key1);
//                        }
//                    }
//                    binIds.put(Long.valueOf(key), sum);
//                }
//            }
//
//        });
//        inventoryStorageVo.setBinIds(binIds);
//        return inventoryStorageVo;
//    }
//
//    private String outInventoryBinIdsGroupingBy(InventoryOutboundVo item) {
//        String binid = "";
//        if (item.getBinIds() != null && item.getBinIds().size() != 0) {
//            for (Long key : item.getBinIds().keySet()) {
//                binid = binid + key;
//            }
//        }
//        return binid;
//    }
//
//    private String outInventoryGroupingBy(InventoryOutboundVo item) {
//        String groupingBy = "";
//        if (ObjectUtils.isNotEmpty(item.getItem().getId())) {
//            groupingBy = groupingBy + item.getItem().getId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getStockId())) {
//            groupingBy = groupingBy + item.getStockId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getFnSku())) {
//            groupingBy = groupingBy + item.getFnSku();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getItem().getId())) {
//            groupingBy = groupingBy + item.getItem().getId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getBatchNo())) {
//            groupingBy = groupingBy + item.getBatchNo();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getShopId())) {
//            groupingBy = groupingBy + item.getShopId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getProjectId())) {
//            groupingBy = groupingBy + item.getProjectId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        return groupingBy;
//    }
//
//    private Long getOutFilterWarehouseBinListByParentId(List<WarehouseBinProducts> filterwarehouseBinProductsList, List<WarehouseBin> zzWarehouseBinList, List<WarehouseBin> zWarehouseBinList, InventoryOutboundVo inventoryStorageVo) throws Exception {
//        List<Long> ids = filterwarehouseBinProductsList.stream().map(s -> s.getParentId()).collect(Collectors.toList());
//        zzWarehouseBinList = zzWarehouseBinList.stream().filter(s -> ids.contains(s.getId())).collect(Collectors.toList());
//        if (CollectionUtils.isEmpty(zzWarehouseBinList)) {
//            return this.getOutFilterWarehouseBinList(zWarehouseBinList, inventoryStorageVo);
//        } else {
//            return zzWarehouseBinList.get(0).getId();
//        }
//    }
//
//    private Long getOutFilterWarehouseBinList(List<WarehouseBin> zWarehouseBinList, InventoryOutboundVo inventoryStorageVo)  throws Exception{
//        zWarehouseBinList = zWarehouseBinList.stream().filter(s -> s.getWarehouseId().equals(inventoryStorageVo.getStockId())).collect(Collectors.toList());
//        if (CollectionUtils.isEmpty(zWarehouseBinList)) {
//            throw new Exception("没有查到对应仓位");
//        }
//        return zWarehouseBinList.get(0).getId();
//    }
//
//    public  InventoryListReturnVo outboundItem(InventoryOutboundVo model,List<Inventory> list, List<InventoryPlacement> list1, List<InventoryBatchNo> list2)  throws Exception{
//        InventoryListReturnVo inventoryListReturnVo=new InventoryListReturnVo();
//        if(model.getQty().compareTo(BigDecimal.ZERO)==0){
//            return new InventoryListReturnVo();
//        }
//        getDocumentType(model.getDocumentType());
//        List<BinIdsVo> binIdsVos =new ArrayList<>();
//        verificationOutbound(model);
//        if (null!=model.getBinIds()&&model.getBinIds().size()>0){
//            binIdsVos= model.getBinIds().entrySet().stream().map(c -> new BinIdsVo(c.getKey(), c.getValue())).collect(Collectors.toList());
//            long sum = binIdsVos.stream().mapToLong(BinIdsVo::getQty).sum();
//            if(QtyIsZeroConfig.isOpen){
//                if(model.getQty().compareTo(BigDecimal.ZERO)==0){
//                    return new InventoryListReturnVo();
//                }
//                if (model.getQty().longValue()!=sum){
//                    throw new Exception("bindIds 为非空时，所有入位数量合计不等于qty");
//                }
//            }else if(sum<=0 || model.getQty().longValue()!=sum){
//                throw new Exception("bindIds为非空时，所有入位数量大于0并且合计不等于qty");
//            }
//        }
//        // 是否开启库龄 只做库龄 表得减  库位 还按原来来的处理
//        if(StockAgeConfig.isOpen){
//            List<InventoryBatchNo> inventoryBatchNoList=this.getOutInventoryBatchNos(model,list2);
//            if (CollectionUtils.isEmpty(inventoryBatchNoList)) {
//                // 是否开启负库存 如果开启
//                if(getIsOpenNegativeInventory(model.getStockId())){
//                    throw new Exception(getItemIdName(model.getItem().getId()) +" 没有查到对应批次库存表数据");
//                }else {
//                    //直接添加
//                    InventoryStorageVo inventoryStorageVo=new InventoryStorageVo();
//                    BeanUtils.copyProperties(model,inventoryStorageVo);
//                    inventoryStorageVo.setTo(model.getFrom());
//                    storageAgeInsert(inventoryStorageVo,inventoryListReturnVo,list2);
//                }
//            }else {
//                // 是否开启负库存
//                if(getIsOpenNegativeInventory(model.getStockId())){
//                    verificationOutboundInventoryBatchNo(model,inventoryBatchNoList);
//                }
//                inventoryListReturnVo.setUpdateInventoryBatchNoList(outboundUpdateBatchNo(model, inventoryBatchNoList));
//            }
//        }
//        List<Inventory> inventoryList = this.getOutInventories(model, list);
//        if (CollectionUtils.isEmpty(inventoryList)) {
//            // 是否开启负库存 如果开启
//            if(getIsOpenNegativeInventory(model.getStockId())){
//                throw new Exception(getItemIdName(model.getItem().getId()) +"没有查到对应库存表数据");
//            }else {
//                //添加新的
//                InventoryStorageVo inventoryStorageVo=new InventoryStorageVo();
//                BeanUtils.copyProperties(model,inventoryStorageVo);
//                inventoryStorageVo.setTo(model.getFrom());
//                storageInsert(inventoryStorageVo, inventoryListReturnVo,binIdsVos,list1);
//            }
//        }else {
//            // 是否开启负库存
//            if(getIsOpenNegativeInventory(model.getStockId())){
//                //校验库存是否满足
//                verificationOutboundInventory(model,inventoryList);
//            }
//            outboundUpdate(model,inventoryList,binIdsVos,inventoryListReturnVo,list1);
//        }
//
//        return inventoryListReturnVo;
//    }
//
//    /**
//     *
//     * @param model
//     * @param inventoryList
//     * @param binIdsVos
//     * @param inventoryListReturnVo
//     */
//    private void outboundUpdate(InventoryOutboundVo model, List<Inventory> inventoryList, List<BinIdsVo> binIdsVos, InventoryListReturnVo inventoryListReturnVo, List<InventoryPlacement> inventoryPlacementList) throws Exception{
//        // 要处理的量
//        BigDecimal qtySum = model.getQty();
//        List<Long> updateIds = new ArrayList<>();
//        List<Long> delIds = new ArrayList<>();
//        List<Long> variationIds = new ArrayList<>();
//        List<Inventory> updateInventoryList=new ArrayList();
//        List<InventoryVariation> inventoryVariationList=new ArrayList();
//
//        for (Inventory inventory : inventoryList) {
//            if (qtySum.compareTo(BigDecimal.ZERO) == 0) {
//                //库存都处理完
//                break;
//            }
//            InventoryVariation inventoryVariation = new InventoryVariation();
//            Inventory updateInventory = new Inventory();
//            updateInventory.setId(inventory.getId());
//            updateInventory.setVersion(inventory.getVersion());
//            BeanUtils.copyProperties(model, inventoryVariation);
//            inventoryVariation.setChangeType("Out");
//            inventoryVariation.setFromType(model.getFrom().getValue());
//            inventoryVariation.setItemId(model.getItem().getId());
//            inventoryVariation.setOperateTime(new Date());
//            inventoryVariation.setStockQty(inventory.getStockQty());
//            inventoryVariation.setLockQty(inventory.getLockQty());
//            inventoryVariation.setDisplayQty(inventory.getDisplayQty());
//            inventoryVariation.setDefectQty(inventory.getDefectQty());
//            inventoryVariation.setWayQty(inventory.getWayQty());
//            inventoryVariation.setStorageQty(inventory.getStorageQty());
//            inventoryVariation.setRejectLockQty(inventory.getRejectLockQty());
//            inventoryVariation.setRejectWayQty(inventory.getRejectWayQty());
//            inventoryVariation.setInspectedQty(inventory.getInspectedQty());
//
//            BigDecimal stockQty = orZero(inventory.getStockQty());
//            BigDecimal lockQty = orZero(inventory.getLockQty());
//            BigDecimal detDefectQty = orZero(inventory.getDefectQty());
//            BigDecimal wayQty = orZero(inventory.getWayQty());
//            BigDecimal displayQty = orZero(inventory.getDisplayQty());
//            BigDecimal normalQty = stockQty.subtract(lockQty).subtract(detDefectQty).subtract(displayQty);
//            BigDecimal storageQty = orZero(inventory.getStorageQty());
//            BigDecimal rejectLockQty = orZero(inventory.getRejectLockQty());
//            BigDecimal rejectWayQty = orZero(inventory.getRejectWayQty());
//            BigDecimal inspectedQty = orZero(inventory.getInspectedQty());
//            BigDecimal pickingQty = orZero(inventory.getPickingQty());
//
//            switch (model.getFrom().getValue()) {
//                case TargetTypeVo.Normal:
//                    if(!getIsOpenNegativeInventory(model.getStockId())){
//                        updateInventory.setStockQty(stockQty.subtract(qtySum));
//                        inventoryVariation.setStockQty(updateInventory.getStockQty());
//                        inventoryVariation.setChangeStockQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    }else if (normalQty.compareTo(qtySum) >= 0) {
//                        updateInventory.setStockQty(stockQty.subtract(qtySum));
//                        inventoryVariation.setStockQty(updateInventory.getStockQty());
//                        inventoryVariation.setChangeStockQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    } else {
//                        updateInventory.setStockQty(stockQty.subtract(normalQty));
//                        inventoryVariation.setStockQty(updateInventory.getStockQty());
//                        inventoryVariation.setChangeStockQty(updateInventory.getStockQty().negate());
//                        qtySum = qtySum.subtract(normalQty);
//                    }
//                    updateInventory.setStockQty(inventoryVariation.getStockQty());
//
//                    break;
//                case TargetTypeVo.Lock:
//                    if(!getIsOpenNegativeInventory(model.getStockId())){
//                        updateInventory.setStockQty(stockQty.subtract(qtySum));
//                        updateInventory.setLockQty(lockQty.subtract(qtySum));
//                        inventoryVariation.setStockQty(updateInventory.getStockQty());
//                        inventoryVariation.setLockQty(updateInventory.getLockQty());
//                        inventoryVariation.setChangeLockQty(qtySum.negate());
//                        inventoryVariation.setChangeStockQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    }else if (lockQty.compareTo(qtySum) >= 0) {
//                        updateInventory.setStockQty(stockQty.subtract(qtySum));
//                        updateInventory.setLockQty(lockQty.subtract(qtySum));
//                        inventoryVariation.setStockQty(updateInventory.getStockQty());
//                        inventoryVariation.setLockQty(updateInventory.getLockQty());
//                        inventoryVariation.setChangeLockQty(qtySum.negate());
//                        inventoryVariation.setChangeStockQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    } else {
//                        updateInventory.setStockQty(stockQty.subtract(lockQty));
//                        updateInventory.setLockQty(BigDecimal.ZERO);
//                        inventoryVariation.setLockQty(updateInventory.getLockQty());
//                        inventoryVariation.setStockQty(updateInventory.getStockQty());
//                        inventoryVariation.setChangeLockQty(lockQty.negate());
//                        inventoryVariation.setChangeStockQty(lockQty.negate());
//                        qtySum = qtySum.subtract(lockQty);
//                    }
//
//                    break;
//                case TargetTypeVo.Display:
//                    if(!getIsOpenNegativeInventory(model.getStockId())){
//                        updateInventory.setStockQty(stockQty.subtract(qtySum));
//                        updateInventory.setDisplayQty(displayQty.subtract(qtySum));
//                        inventoryVariation.setDisplayQty(updateInventory.getDisplayQty());
//                        inventoryVariation.setStockQty(updateInventory.getStockQty());
//                        inventoryVariation.setChangeDisplayQty(qtySum.negate());
//                        inventoryVariation.setChangeStockQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    }else if (displayQty.compareTo(qtySum) >= 0) {
//                        updateInventory.setStockQty(stockQty.subtract(qtySum));
//                        updateInventory.setDisplayQty(displayQty.subtract(qtySum));
//                        inventoryVariation.setDisplayQty(updateInventory.getDisplayQty());
//                        inventoryVariation.setStockQty(updateInventory.getStockQty());
//                        inventoryVariation.setChangeDisplayQty(qtySum.negate());
//                        inventoryVariation.setChangeStockQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    } else {
//                        updateInventory.setLockQty(BigDecimal.ZERO);
//                        updateInventory.setStockQty(stockQty.subtract(displayQty));
//                        inventoryVariation.setLockQty(updateInventory.getLockQty());
//                        inventoryVariation.setStockQty(updateInventory.getStockQty());
//                        inventoryVariation.setChangeLockQty(displayQty.negate());
//                        inventoryVariation.setChangeStockQty(displayQty.negate());
//                        qtySum = qtySum.subtract(displayQty);
//                    }
//                    break;
//                case TargetTypeVo.Defect:
//                    if(!getIsOpenNegativeInventory(model.getStockId())){
//                        updateInventory.setStockQty(stockQty.subtract(qtySum));
//                        updateInventory.setDefectQty(detDefectQty.subtract(qtySum));
//                        inventoryVariation.setStockQty(updateInventory.getStockQty());
//                        inventoryVariation.setDefectQty(updateInventory.getDefectQty());
//                        inventoryVariation.setChangeStockQty(qtySum.negate());
//                        inventoryVariation.setChangeDefectQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    }else if (detDefectQty.compareTo(qtySum) >= 0) {
//                        updateInventory.setStockQty(stockQty.subtract(qtySum));
//                        updateInventory.setDefectQty(detDefectQty.subtract(qtySum));
//                        inventoryVariation.setStockQty(updateInventory.getStockQty());
//                        inventoryVariation.setDefectQty(updateInventory.getDefectQty());
//                        inventoryVariation.setChangeStockQty(qtySum.negate());
//                        inventoryVariation.setChangeDefectQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    } else {
//                        updateInventory.setStockQty(stockQty.subtract(detDefectQty));
//                        updateInventory.setDefectQty(BigDecimal.ZERO);
//                        inventoryVariation.setStockQty(updateInventory.getStockQty());
//                        inventoryVariation.setDefectQty(updateInventory.getDefectQty());
//                        inventoryVariation.setChangeStockQty(detDefectQty.negate());
//                        inventoryVariation.setDefectQty(detDefectQty.negate());
//                        qtySum = qtySum.subtract(detDefectQty);
//                    }
//                    break;
//                case TargetTypeVo.Way:
//                    if(!getIsOpenNegativeInventory(model.getStockId())){
//                        updateInventory.setWayQty(wayQty.subtract(qtySum));
//                        inventoryVariation.setWayQty(updateInventory.getWayQty());
//                        inventoryVariation.setChangeWayQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    }else  if (wayQty.compareTo(qtySum) >= 0) {
//                        updateInventory.setWayQty(wayQty.subtract(qtySum));
//                        inventoryVariation.setWayQty(updateInventory.getWayQty());
//                        inventoryVariation.setChangeWayQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    } else {
//                        updateInventory.setWayQty(BigDecimal.ZERO);
//                        inventoryVariation.setWayQty(updateInventory.getWayQty());
//                        inventoryVariation.setChangeWayQty(wayQty.negate());
//                        qtySum = qtySum.subtract(wayQty);
//                    }
//                    break;
//                case TargetTypeVo.Storage:
//                    if(!getIsOpenNegativeInventory(model.getStockId())){
//                        updateInventory.setStorageQty(storageQty.subtract(qtySum));
//                        inventoryVariation.setStorageQty(updateInventory.getStorageQty());
//                        inventoryVariation.setChangeStorageQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    }else  if (storageQty.compareTo(qtySum) >= 0) {
//                        updateInventory.setStorageQty(storageQty.subtract(qtySum));
//                        inventoryVariation.setStorageQty(updateInventory.getStorageQty());
//                        inventoryVariation.setChangeStorageQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    } else {
//                        updateInventory.setStorageQty(BigDecimal.ZERO);
//                        inventoryVariation.setStorageQty(updateInventory.getStorageQty());
//                        inventoryVariation.setChangeStorageQty(storageQty.negate());
//                        qtySum = qtySum.subtract(storageQty);
//                    }
//                    break;
//                case TargetTypeVo.RejectLock:
//                    if(!getIsOpenNegativeInventory(model.getStockId())){
//                        updateInventory.setRejectLockQty(rejectLockQty.subtract(qtySum));
//                        inventoryVariation.setRejectLockQty(updateInventory.getRejectLockQty());
//                        inventoryVariation.setChangeRejectLockQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    }else  if (rejectLockQty.compareTo(qtySum) >= 0) {
//                        updateInventory.setRejectLockQty(rejectLockQty.subtract(qtySum));
//                        inventoryVariation.setRejectLockQty(updateInventory.getRejectLockQty());
//                        inventoryVariation.setChangeRejectLockQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    } else {
//                        updateInventory.setRejectLockQty(BigDecimal.ZERO);
//                        inventoryVariation.setRejectLockQty(updateInventory.getRejectLockQty());
//                        inventoryVariation.setChangeRejectLockQty(rejectLockQty.negate());
//                        qtySum = qtySum.subtract(rejectLockQty);
//                    }
//                    break;
//                case TargetTypeVo.RejectWay:
//                    if(!getIsOpenNegativeInventory(model.getStockId())){
//                        updateInventory.setRejectWayQty(rejectWayQty.subtract(qtySum));
//                        inventoryVariation.setRejectWayQty(updateInventory.getRejectWayQty());
//                        inventoryVariation.setChangeRejectWayQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    }else  if (rejectWayQty.compareTo(qtySum) >= 0) {
//                        updateInventory.setRejectWayQty(rejectWayQty.subtract(qtySum));
//                        inventoryVariation.setRejectWayQty(updateInventory.getRejectWayQty());
//                        inventoryVariation.setChangeRejectWayQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    } else {
//                        updateInventory.setRejectWayQty(BigDecimal.ZERO);
//                        inventoryVariation.setRejectWayQty(updateInventory.getRejectWayQty());
//                        inventoryVariation.setChangeRejectWayQty(rejectWayQty.negate());
//                        qtySum = qtySum.subtract(rejectWayQty);
//                    }
//                    break;
//                case TargetTypeVo.Inspected:
//                    if(!getIsOpenNegativeInventory(model.getStockId())){
//                        updateInventory.setInspectedQty(inspectedQty.subtract(qtySum));
//                        inventoryVariation.setInspectedQty(updateInventory.getInspectedQty());
//                        inventoryVariation.setChangeInspectedQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    }else  if (inspectedQty.compareTo(qtySum) >= 0) {
//                        updateInventory.setInspectedQty(inspectedQty.subtract(qtySum));
//                        inventoryVariation.setInspectedQty(updateInventory.getInspectedQty());
//                        inventoryVariation.setChangeInspectedQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    } else {
//                        updateInventory.setInspectedQty(BigDecimal.ZERO);
//                        inventoryVariation.setInspectedQty(updateInventory.getInspectedQty());
//                        inventoryVariation.setChangeInspectedQty(inspectedQty.negate());
//                        qtySum = qtySum.subtract(inspectedQty);
//                    }
//                    break;
//                case TargetTypeVo.Picking:
//                    if(!getIsOpenNegativeInventory(model.getStockId())){
//                        updateInventory.setPickingQty(pickingQty.subtract(qtySum));
//                        inventoryVariation.setPickingQty(updateInventory.getPickingQty());
//                        inventoryVariation.setChangePickingQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    }else  if (pickingQty.compareTo(qtySum) >= 0) {
//                        updateInventory.setPickingQty(pickingQty.subtract(qtySum));
//                        inventoryVariation.setPickingQty(updateInventory.getPickingQty());
//                        inventoryVariation.setChangePickingQty(qtySum.negate());
//                        qtySum = BigDecimal.ZERO;
//                    } else {
//                        updateInventory.setPickingQty(BigDecimal.ZERO);
//                        inventoryVariation.setPickingQty(updateInventory.getPickingQty());
//                        inventoryVariation.setChangePickingQty(pickingQty.negate());
//                        qtySum = qtySum.subtract(pickingQty);
//                    }
//                    break;
//
//                default:
//                    throw new Exception("出库源类型不明确");
//            }
//            updateInventoryList.add(updateInventory);
//            inventoryVariationList.add(inventoryVariation);
//            if (binIdsVos.size() != 0) {
//                updateOutInentoryPlacement(inventoryListReturnVo,inventoryPlacementList,model, binIdsVos);
//            };
//
//        }
//        inventoryListReturnVo.setInsertInventoryVariations(inventoryVariationList);
//        inventoryListReturnVo.setUpdateInventoryList(updateInventoryList);
//    }
//
//    private void updateOutInentoryPlacement(InventoryListReturnVo inventoryListReturnVo,List<InventoryPlacement> list,InventoryOutboundVo model, List<BinIdsVo> binIdsVos) throws Exception {
//        List<InventoryPlacement> insertInventoryPlacementList=new ArrayList<>();
//        List<InventoryPlacement> updateInventoryPlacementList=new ArrayList<>();
//        List<InventoryPlacementVariation> addsInventoryPlacementVariation=new ArrayList<>();
//        for (BinIdsVo binIdsVo : binIdsVos) {
//            List<InventoryPlacement>  inventoryPlacementList=getOutInventoryPlacementList(model, binIdsVo.getBinId(),  list);
//            if (CollectionUtils.isEmpty(inventoryPlacementList)) {
//                if(getIsOpenNegativeInventory(model.getStockId())){
//                    throw new Exception(getItemIdName(model.getItem().getId())+"没有对应库位内码");
//                }else {
//                    InventoryPlacement insertInventoryPlacement = new InventoryPlacement();
//                    BeanUtils.copyProperties(model, insertInventoryPlacement);
//                    insertInventoryPlacement.setBinId(binIdsVo.getBinId());
//                    insertInventoryPlacement.setAuxId(insertInventoryPlacement.getAuxId());
//                    insertInventoryPlacement.setAuxQty(insertInventoryPlacement.getAuxQty());
//                    insertInventoryPlacement.setItemId(model.getItem().getId());
//                    InventoryPlacementVariation inventoryPlacementVariation =new InventoryPlacementVariation();
//                    BeanUtils.copyProperties(model, inventoryPlacementVariation);
//                    inventoryPlacementVariation.setChangeType("Out");
//                    inventoryPlacementVariation.setFromType(model.getFromBinIdsType().getValue());
//                    inventoryPlacementVariation.setItemId(model.getItem().getId());
//                    inventoryPlacementVariation.setOperateTime(new Date());
//                    inventoryPlacementVariation.setBinId(binIdsVo.getBinId());
//                    inventoryPlacementVariation.setBinId(insertInventoryPlacement.getBinId());
//                    if (StringUtils.isBlank(model.getBatchNo())) {
//                        insertInventoryPlacement.setBatchNo(null);
//                    }
//                    switch (model.getFromBinIdsType().getValue()) {
//                        case TargetTypeVo.Normal:
//                            inventoryPlacementVariation.setStockQty(new BigDecimal(binIdsVo.getQty()));
//                            inventoryPlacementVariation.setChangeStockQty(new BigDecimal(binIdsVo.getQty()));
//                            insertInventoryPlacement.setStockQty(new BigDecimal(binIdsVo.getQty()));
//                            insertInventoryPlacement.setLockQty(null);
//                            insertInventoryPlacement.setWayQty(null);
//                            break;
//                        case TargetTypeVo.Way:
//                            inventoryPlacementVariation.setWayQty(new BigDecimal(binIdsVo.getQty()));
//                            inventoryPlacementVariation.setChangeWayQty(new BigDecimal(binIdsVo.getQty()));
//                            insertInventoryPlacement.setWayQty(new BigDecimal(binIdsVo.getQty()));
//                            insertInventoryPlacement.setStockQty(null);
//                            insertInventoryPlacement.setLockQty(null);
//                            break;
//                        case TargetTypeVo.Lock:
//                            inventoryPlacementVariation.setLockQty(new BigDecimal(binIdsVo.getQty()));
//                            inventoryPlacementVariation.setChangeLockQty(new BigDecimal(binIdsVo.getQty()));
//                            insertInventoryPlacement.setLockQty(new BigDecimal(binIdsVo.getQty()));
//                            insertInventoryPlacement.setStockQty(null);
//                            insertInventoryPlacement.setWayQty(null);
//                            break;
//                        default:
//                            throw new Exception("入库位目标类型不正确");
//                    }
//                    insertInventoryPlacementList.add(insertInventoryPlacement);
//                    addsInventoryPlacementVariation.add(inventoryPlacementVariation);
//                }
//            }else {
//                getVerificationOutInventoryPlacement(model, binIdsVo, inventoryPlacementList);
//                BigDecimal outQtySum= new BigDecimal(binIdsVo.getQty());
//                for (InventoryPlacement inventoryPlacement : inventoryPlacementList) {
//                    if(outQtySum.compareTo(BigDecimal.ZERO)==0){
//                        break;
//                    }
//                    InventoryPlacement updateInventoryPlacement=new InventoryPlacement();
//                    updateInventoryPlacement.setId(inventoryPlacement.getId());
//                    updateInventoryPlacement.setVersion(inventoryPlacement.getVersion());
//                    InventoryPlacementVariation inventoryPlacementVariation =new InventoryPlacementVariation();
//                    BeanUtils.copyProperties(model, inventoryPlacementVariation);
//                    inventoryPlacementVariation.setChangeType("Out");
//                    inventoryPlacementVariation.setFromType(model.getFromBinIdsType().getValue());
//                    inventoryPlacementVariation.setItemId(model.getItem().getId());
//                    inventoryPlacementVariation.setOperateTime(new Date());
//                    inventoryPlacementVariation.setBinId(inventoryPlacement.getBinId());
//                    inventoryPlacementVariation.setStockQty(inventoryPlacement.getStockQty());
//                    inventoryPlacementVariation.setLockQty(inventoryPlacement.getLockQty());
//                    inventoryPlacementVariation.setWayQty(inventoryPlacement.getWayQty());
//
//                    switch (model.getFromBinIdsType().getValue()) {
//                        case TargetTypeVo.Normal:
//                            if(inventoryPlacement.getStockQty()==null){
//                                inventoryPlacement.setStockQty(new BigDecimal(0));
//                            }
//                            if(outQtySum.compareTo(BigDecimal.ZERO)==0){
//                                break;
//                            }else if(!getIsOpenNegativeInventory(model.getStockId())){
//                                inventoryPlacementVariation.setChangeStockQty(new BigDecimal(binIdsVo.getQty()).negate() );
//                                inventoryPlacementVariation.setStockQty(inventoryPlacement.getStockQty().subtract(new BigDecimal(binIdsVo.getQty())));
//                                updateInventoryPlacement.setStockQty(inventoryPlacement.getStockQty().subtract(outQtySum));
//                                outQtySum=BigDecimal.ZERO;
//                            }else if(outQtySum.compareTo(inventoryPlacement.getStockQty())>=0){
//                                inventoryPlacementVariation.setChangeStockQty(inventoryPlacement.getStockQty().negate() );
//                                inventoryPlacementVariation.setStockQty(BigDecimal.ZERO);
//                                outQtySum=outQtySum.subtract(inventoryPlacement.getStockQty());
//                                updateInventoryPlacement.setStockQty(BigDecimal.ZERO);
//
//                            }else if (outQtySum.compareTo(inventoryPlacement.getStockQty())==-1){
//                                inventoryPlacementVariation.setChangeStockQty(outQtySum.negate());
//                                inventoryPlacementVariation.setStockQty(inventoryPlacement.getStockQty().subtract(outQtySum));
//                                updateInventoryPlacement.setStockQty(inventoryPlacement.getStockQty().subtract(outQtySum));
//                                outQtySum=BigDecimal.ZERO;
//                            }
//
//                            break;
//                        case TargetTypeVo.Lock:
//                            if(inventoryPlacement.getLockQty()==null){
//                                inventoryPlacement.setLockQty(new BigDecimal(0));
//                            }
//                            if(outQtySum.compareTo(BigDecimal.ZERO)==0){
//                                break;
//                            }else if(!getIsOpenNegativeInventory(model.getStockId())){
//                                inventoryPlacementVariation.setChangeLockQty(new BigDecimal(binIdsVo.getQty()).negate());
//                                inventoryPlacementVariation.setLockQty(inventoryPlacement.getLockQty().subtract(new BigDecimal(binIdsVo.getQty())));
//                                updateInventoryPlacement.setLockQty(inventoryPlacement.getLockQty().subtract(outQtySum));
//
//                                outQtySum=BigDecimal.ZERO;
//                            }else if(outQtySum.compareTo(inventoryPlacement.getLockQty())>=0){
//                                inventoryPlacementVariation.setChangeLockQty(inventoryPlacement.getLockQty().negate() );
//                                inventoryPlacementVariation.setLockQty(BigDecimal.ZERO);
//                                outQtySum=outQtySum.subtract(inventoryPlacement.getLockQty());
//                                updateInventoryPlacement.setLockQty(BigDecimal.ZERO);
//
//                            }else if (outQtySum.compareTo(inventoryPlacement.getLockQty())==-1){
//                                inventoryPlacementVariation.setChangeLockQty(outQtySum.negate() );
//                                inventoryPlacementVariation.setLockQty(inventoryPlacement.getLockQty().subtract(outQtySum));
//                                updateInventoryPlacement.setLockQty(inventoryPlacement.getLockQty().subtract(outQtySum));
//                                outQtySum=BigDecimal.ZERO;
//                            }
//                            break;
//                        case TargetTypeVo.Way:
//                            if(inventoryPlacement.getWayQty()==null){
//                                inventoryPlacement.setWayQty(new BigDecimal(0));
//                            }
//                            if(outQtySum.compareTo(BigDecimal.ZERO)==0){
//                                break;
//                            }else if(!getIsOpenNegativeInventory(model.getStockId())){
//                                inventoryPlacementVariation.setChangeWayQty(new BigDecimal(binIdsVo.getQty()).negate());
//                                inventoryPlacementVariation.setWayQty(inventoryPlacement.getWayQty().subtract(new BigDecimal(binIdsVo.getQty())));
//                                updateInventoryPlacement.setWayQty(inventoryPlacement.getWayQty().subtract(outQtySum));
//                                outQtySum=BigDecimal.ZERO;
//                            }else if(outQtySum.compareTo(inventoryPlacement.getWayQty())>=0){
//                                inventoryPlacementVariation.setChangeWayQty(inventoryPlacement.getWayQty().negate() );
//                                inventoryPlacementVariation.setWayQty(BigDecimal.ZERO);
//                                outQtySum=outQtySum.subtract(inventoryPlacement.getWayQty());
//                                updateInventoryPlacement.setWayQty(BigDecimal.ZERO);
//                            }else if (outQtySum.compareTo(inventoryPlacement.getWayQty())==-1){
//                                inventoryPlacementVariation.setChangeWayQty(outQtySum.negate() );
//                                inventoryPlacementVariation.setWayQty(inventoryPlacement.getWayQty().subtract(outQtySum));
//                                updateInventoryPlacement.setWayQty(inventoryPlacement.getWayQty().subtract(outQtySum));
//                                outQtySum=BigDecimal.ZERO;
//                            }
//                            break;
//                        default:
//                            throw new Exception("出库位类型不明确");
//                    }
//                    addsInventoryPlacementVariation.add(inventoryPlacementVariation);
//                    updateInventoryPlacementList.add(updateInventoryPlacement);
//                }
//            }
//        }
//        inventoryListReturnVo.setInventoryPlacement(insertInventoryPlacementList);;
//        inventoryListReturnVo.setUpdateInventoryPlacementList(updateInventoryPlacementList);
//        inventoryListReturnVo.setInventoryPlacementVariations(addsInventoryPlacementVariation);
//    }
//
//    private List<InventoryPlacement> getOutInventoryPlacementList(InventoryOutboundVo inventoryStorageVo, Long binId, List<InventoryPlacement> list1) {
//        list1 = list1.stream().filter(s -> s.getItemId().equals(inventoryStorageVo.getItem().getId()) && s.getBinId().equals(binId)).collect(Collectors.toList());
//        if (inventoryStorageVo.getBatchNo() == null) {
//            list1 = list1.stream().filter(s -> s.getBatchNo() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getBatchNo() != null).filter(s -> s.getBatchNo().equals(inventoryStorageVo.getBatchNo())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getStockId() == null) {
//            list1 = list1.stream().filter(s -> s.getStockId() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getStockId() != null).filter(s -> s.getStockId().equals(inventoryStorageVo.getStockId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getFnSku() == null) {
//            list1 = list1.stream().filter(s -> s.getFnSku() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getFnSku() != null).filter(s -> s.getFnSku().equals(inventoryStorageVo.getFnSku())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getShopId() == null) {
//            list1 = list1.stream().filter(s -> s.getShopId() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getShopId() != null).filter(s -> s.getShopId().equals(inventoryStorageVo.getShopId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getProjectId() == null) {
//            list1 = list1.stream().filter(s -> s.getProjectId() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getProjectId() != null).filter(s -> s.getProjectId().equals(inventoryStorageVo.getProjectId())).collect(Collectors.toList());
//        }
//        return  list1;
//    }
//
//    //校验
//    private void getVerificationOutInventoryPlacement(InventoryOutboundVo model, BinIdsVo binIdsVo, List<InventoryPlacement> inventoryPlacementList) throws Exception {
//        BigDecimal stockQtySum= inventoryPlacementList.stream().filter(c -> c.getStockQty() != null).map(InventoryPlacement::getStockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal LockQtySum= inventoryPlacementList.stream().filter(c -> c.getLockQty() != null).map(InventoryPlacement::getLockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal WayQtySum= inventoryPlacementList.stream().filter(c -> c.getWayQty() != null).map(InventoryPlacement::getWayQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//        if(getIsOpenNegativeInventory(model.getStockId())){
//            switch (model.getFromBinIdsType().getValue()) {
//                case TargetTypeVo.Normal:
//                    if(stockQtySum.compareTo(new BigDecimal(binIdsVo.getQty()))==-1){
//                        throw new Exception("库存货位放置表正常库存不足");
//                    }
//                    break;
//                case TargetTypeVo.Lock:
//                    if(LockQtySum.compareTo(new BigDecimal(binIdsVo.getQty()))==-1){
//                        throw new Exception("库存货位放置表锁定库存不足");
//                    }
//                    break;
//                case TargetTypeVo.Way:
//                    if(WayQtySum.compareTo(new BigDecimal(binIdsVo.getQty()))==-1){
//                        throw new Exception("库存货位放置表在途库存不足");
//                    }
//                    break;
//                default:
//                    throw new Exception("出库位类型不明确");
//            }
//        }else {
//            switch (model.getFromBinIdsType().getValue()) {
//                case TargetTypeVo.Normal:
//                    break;
//                case TargetTypeVo.Lock:
//                    break;
//                case TargetTypeVo.Way:
//                    break;
//                default:
//                    throw new Exception("出库位类型不明确");
//            }
//        }
//    }
//
//    private void verificationOutboundInventory(InventoryOutboundVo model, List<Inventory> inventoryList) throws Exception {
//        //校验库存是否有那么多
//        BigDecimal stockQty= inventoryList.stream().filter(c -> c.getStockQty() != null).map(Inventory::getStockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal lockQty= inventoryList.stream().filter(c -> c.getLockQty() != null).map(Inventory::getLockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal detDefectQty= inventoryList.stream().filter(c -> c.getDefectQty() != null).map(Inventory::getDefectQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal displayQty= inventoryList.stream().filter(c -> c.getDisplayQty() != null).map(Inventory::getDisplayQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal wayQty= inventoryList.stream().filter(c -> c.getWayQty() != null).map(Inventory::getWayQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal storageQty= inventoryList.stream().filter(c -> c.getStorageQty() != null).map(Inventory::getStorageQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal rejectLockQty= inventoryList.stream().filter(c -> c.getRejectLockQty() != null).map(Inventory::getRejectLockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal rejectWayQty= inventoryList.stream().filter(c -> c.getRejectWayQty() != null).map(Inventory::getRejectWayQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal inspectedQty= inventoryList.stream().filter(c -> c.getInspectedQty() != null).map(Inventory::getInspectedQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal pickingQty= inventoryList.stream().filter(c -> c.getPickingQty() != null).map(Inventory::getPickingQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//
//
//        switch (model.getFrom().getValue()) {
//            case TargetTypeVo.Normal:
//                //减去 对应的锁库 残次 的 不能大于当前的库存
//                BigDecimal qty =stockQty.subtract(lockQty.add(detDefectQty).add(displayQty));
//                if(qty.compareTo(model.getQty()) < 0){
//                    //throw new InventoryException(model.getItem().getId(),itemIdName+" 出库数量大于库存数量-锁库数量-残次数量 库存数："+stockQty.subtract(lockQty.add(detDefectQty)));
//                    throw new InventoryException(model.getItem().getId(),getItemIdName(model.getItem().getId())+"  库存不足："+model.getQty().subtract(qty));
//                }
//                break;
//            case TargetTypeVo.Lock:
//                if(lockQty.compareTo(model.getQty()) < 0){
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId())+" 锁库库存不足："+model.getQty().subtract(lockQty));
//                }
//                break;
//            case TargetTypeVo.Display:
//                if(displayQty.compareTo(model.getQty()) < 0){
//                    throw new InventoryException(model.getItem().getId(),getItemIdName(model.getItem().getId())+ " 展品库存不足："+model.getQty().subtract(displayQty));
//                }
//                break;
//            case TargetTypeVo.Defect:
//                if(detDefectQty.compareTo(model.getQty()) < 0){
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId())+" 残次库存不足："+model.getQty().subtract(detDefectQty));
//                }
//                break;
//            case TargetTypeVo.Way:
//                if(wayQty.compareTo(model.getQty()) < 0){
//                    throw new InventoryException(model.getItem().getId(),getItemIdName(model.getItem().getId())+" 在途库存不足："+model.getQty().subtract(wayQty));
//                }
//                break;
//            case TargetTypeVo.Storage:
//                if(storageQty.compareTo(model.getQty()) < 0){
//                    throw new InventoryException(model.getItem().getId(),getItemIdName(model.getItem().getId())+" 暂存库存不足："+model.getQty().subtract(storageQty));
//                }
//                break;
//            case TargetTypeVo.RejectLock:
//                if(rejectLockQty.compareTo(model.getQty()) < 0){
//                    throw new InventoryException(model.getItem().getId(),getItemIdName(model.getItem().getId())+" 次品锁定库存不足："+model.getQty().subtract(rejectLockQty));
//                }
//                break;
//            case TargetTypeVo.RejectWay:
//                if(rejectWayQty.compareTo(model.getQty()) < 0){
//                    throw new InventoryException(model.getItem().getId(),getItemIdName(model.getItem().getId())+" 次品在途库存不足："+model.getQty().subtract(rejectWayQty));
//                }
//                break;
//            case TargetTypeVo.Inspected:
//                if(inspectedQty.compareTo(model.getQty()) < 0){
//                    throw new InventoryException(model.getItem().getId(),getItemIdName(model.getItem().getId())+" 待检库存不足："+model.getQty().subtract(inspectedQty));
//                }
//                break;
//            case TargetTypeVo.Picking:
//                if(pickingQty.compareTo(model.getQty()) < 0){
//                    throw new InventoryException(model.getItem().getId(),getItemIdName(model.getItem().getId())+" 拣货库存不足："+model.getQty().subtract(pickingQty));
//                }
//                break;
//            default:
//                throw new Exception("出库源类型不明确");
//        }
//    }
//    private List<InventoryBatchNo> getOutInventoryBatchNos(InventoryOutboundVo inventoryStorageVo, List<InventoryBatchNo> inventoryList) {
//
//
//        inventoryList = inventoryList.stream().filter(s -> s.getItemId().equals(inventoryStorageVo.getItem().getId())).collect(Collectors.toList());
//        if (inventoryStorageVo.getBatchNo() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getBatchNo() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getBatchNo() != null).filter(s -> s.getBatchNo().equals(inventoryStorageVo.getBatchNo())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getStockId() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getStockId() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getStockId() != null).filter(s -> s.getStockId().equals(inventoryStorageVo.getStockId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getFnSku() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getFnSku() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getFnSku() != null).filter(s -> s.getFnSku().equals(inventoryStorageVo.getFnSku())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getShopId() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getShopId() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getShopId() != null).filter(s -> s.getShopId().equals(inventoryStorageVo.getShopId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getProjectId() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getProjectId() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getProjectId() != null).filter(s -> s.getProjectId().equals(inventoryStorageVo.getProjectId())).collect(Collectors.toList());
//        }
//        return inventoryList;
//    }
//
//    private List<Inventory> getOutInventories(InventoryOutboundVo inventoryStorageVo, List<Inventory> inventoryList) {
//        inventoryList = inventoryList.stream().filter(s -> s.getItemId().equals(inventoryStorageVo.getItem().getId())).collect(Collectors.toList());
//        if (inventoryStorageVo.getBatchNo() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getBatchNo() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getBatchNo() != null).filter(s -> s.getBatchNo().equals(inventoryStorageVo.getBatchNo())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getStockId() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getStockId() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getStockId() != null).filter(s -> s.getStockId().equals(inventoryStorageVo.getStockId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getFnSku() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getFnSku() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getFnSku() != null).filter(s -> s.getFnSku().equals(inventoryStorageVo.getFnSku())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getShopId() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getShopId() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getShopId() != null).filter(s -> s.getShopId().equals(inventoryStorageVo.getShopId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getProjectId() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getProjectId() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getProjectId() != null).filter(s -> s.getProjectId().equals(inventoryStorageVo.getProjectId())).collect(Collectors.toList());
//        }
//        return inventoryList;
//    }
//
//    /**
//     *
//     * @param model  校验出库数据
//     * @throws Exception
//     */
//    private void verificationOutbound(InventoryOutboundVo model) throws Exception {
//        if (null==model.getStockId()){
//            throw new Exception("stockId 为空");
//        }
//        if (ObjectUtils.allNull(model.getItem())){
//            throw new Exception("item 为空");
//
//        }
//        if(Boolean.TRUE.equals(model.getItem().getBatchManagement())&& StringUtils.isBlank(model.getBatchNo())){
//            throw new Exception("item.batchManagement == true 时 batchNo 为空");
//        }
//
//        if(QtyIsZeroConfig.isOpen){
//            if (model.getQty() == null){
//                throw new Exception("操作数量不能为空");
//            }
//        }else if (model.getQty() == null || BigDecimal.ZERO.equals(model.getQty())) {
//            throw new Exception("操作数量不能为空或零");
//        }
//        if (!Boolean.TRUE.equals(model.getSupportNegative()) && model.getQty().compareTo(BigDecimal.ZERO)<0) {
//            throw new Exception("操作数量不能为负数");
//        }
//    }
//
//    private List<WarehouseBinProducts> getOutFilterWarehouseProductsBinList(List<WarehouseBinProducts> list, InventoryOutboundVo inventoryStorageVo) {
//        list.stream().filter(s -> s.getProductId().equals(inventoryStorageVo.getItem().getId()));
//        if (ObjectUtils.isEmpty(inventoryStorageVo.getShopId())) {
//            list = list.stream().filter(s -> s.getShopId() == null).collect(Collectors.toList());
//        } else {
//            list = list.stream().filter(s -> s.getShopId() != null).filter(s -> s.getShopId().equals(inventoryStorageVo.getShopId())).collect(Collectors.toList());
//        }
//        if (ObjectUtils.isEmpty(inventoryStorageVo.getFnSku())) {
//            list = list.stream().filter(s -> s.getFnsku() == null).collect(Collectors.toList());
//        } else {
//            list = list.stream().filter(s -> s.getFnsku() != null).filter(s -> s.getFnsku().equals(inventoryStorageVo.getFnSku())).collect(Collectors.toList());
//        }
//        return list;
//    }
//
//
//
//
//    /**
//     * @param filterwarehouseBinProductsList 过滤后的子表数据
//     * @param zzWarehouseBinList             主子关系
//     * @param zWarehouseBinList              主表得仓库
//     * @param inventoryStorageVo             数据
//     * @return
//     */
//    private Long getFilterWarehouseBinListByParentId(List<WarehouseBinProducts> filterwarehouseBinProductsList, List<WarehouseBin> zzWarehouseBinList, List<WarehouseBin> zWarehouseBinList, InventoryStorageVo inventoryStorageVo) throws Exception {
//        List<Long> ids = filterwarehouseBinProductsList.stream().map(s -> s.getParentId()).collect(Collectors.toList());
//        zzWarehouseBinList = zzWarehouseBinList.stream().filter(s -> ids.contains(s.getId())).collect(Collectors.toList());
//        if (CollectionUtils.isEmpty(zzWarehouseBinList)) {
//            return this.getFilterWarehouseBinList(zWarehouseBinList, inventoryStorageVo);
//        } else {
//            return zzWarehouseBinList.get(0).getId();
//        }
//    }
//
//    private Long getFilterWarehouseBinList(List<WarehouseBin> zWarehouseBinList, InventoryStorageVo inventoryStorageVo) throws Exception {
//        zWarehouseBinList = zWarehouseBinList.stream().filter(s -> s.getWarehouseId().equals(inventoryStorageVo.getStockId())).collect(Collectors.toList());
//        if (CollectionUtils.isEmpty(zWarehouseBinList)) {
//            throw new Exception("没有查到对应仓位");
//        }
//        return zWarehouseBinList.get(0).getId();
//    }
//
//    private List<WarehouseBinProducts> getFilterWarehouseProductsBinList(List<WarehouseBinProducts> list, InventoryStorageVo inventoryStorageVo) {
//        list.stream().filter(s -> s.getProductId().equals(inventoryStorageVo.getItem().getId()));
//        if (ObjectUtils.isEmpty(inventoryStorageVo.getShopId())) {
//            list = list.stream().filter(s -> s.getShopId() == null).collect(Collectors.toList());
//        } else {
//            list = list.stream().filter(s -> s.getShopId() != null).filter(s -> s.getShopId().equals(inventoryStorageVo.getStockId())).collect(Collectors.toList());
//        }
//        if (ObjectUtils.isEmpty(inventoryStorageVo.getFnSku())) {
//            list = list.stream().filter(s -> s.getFnsku() == null).collect(Collectors.toList());
//        } else {
//            list = list.stream().filter(s -> s.getFnsku() != null).filter(s -> s.getFnsku().equals(inventoryStorageVo.getFnSku())).collect(Collectors.toList());
//        }
//        return list;
//    }
//
//    //入库数量合并
//    private InventoryStorageVo numMergeInventoryStorageVo(List<InventoryStorageVo> valueList) {
//        InventoryStorageVo inventoryStorageVo = valueList.get(0);
//        BigDecimal sumQty = valueList.stream().map(InventoryStorageVo::getQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        inventoryStorageVo.setQty(sumQty);
//        Map<String, List<InventoryStorageVo>> listMap = valueList
//                .stream()
//                .collect(Collectors.groupingBy(item -> this.inventoryBinIdsGroupingBy(item)
//                ));
//        Map<Long, Integer> binIds = new HashMap<>();
//        listMap.forEach((key, itemList) -> {
//            if (!ObjectUtils.isEmpty(key)) {
//                if (itemList.size() == 1) {
//                    binIds.putAll(itemList.get(0).getBinIds());
//                } else {
//                    Integer sum = 0;
//                    for (InventoryStorageVo storageVo : itemList) {
//                        Map<Long, Integer> binIds1 = storageVo.getBinIds();
//                        for (Long key1 : binIds1.keySet()) {
//                            sum = sum + binIds1.get(key1);
//                        }
//                    }
//                    binIds.put(Long.valueOf(key), sum);
//                }
//            }
//
//        });
//        inventoryStorageVo.setBinIds(binIds);
//        return inventoryStorageVo;
//    }
//
//    private String inventoryBinIdsGroupingBy(InventoryStorageVo item) {
//        String binid = "";
//        if (item.getBinIds() != null && item.getBinIds().size() != 0) {
//            for (Long key : item.getBinIds().keySet()) {
//                binid = binid + key;
//            }
//        }
//        return binid;
//    }
//
//    private String inventoryGroupingBy(InventoryStorageVo item) {
//        String groupingBy = "";
//        if (ObjectUtils.isNotEmpty(item.getItem().getId())) {
//            groupingBy = groupingBy + item.getItem().getId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getStockId())) {
//            groupingBy = groupingBy + item.getStockId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getFnSku())) {
//            groupingBy = groupingBy + item.getFnSku();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getItem().getId())) {
//            groupingBy = groupingBy + item.getItem().getId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getBatchNo())) {
//            groupingBy = groupingBy + item.getBatchNo();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getShopId())) {
//            groupingBy = groupingBy + item.getShopId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getExpiryDate())) {
//            groupingBy = groupingBy + item.getExpiryDate();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        if (ObjectUtils.isNotEmpty(item.getProjectId())) {
//            groupingBy = groupingBy + item.getProjectId();
//        } else {
//            groupingBy = groupingBy + "-";
//        }
//        return groupingBy;
//    }
//
//    //入库进行处理
//    private InventoryListReturnVo storageItem(InventoryStorageVo inventoryStorageVo, List<Inventory> list, List<InventoryPlacement> list1, List<InventoryBatchNo> list2) throws Exception {
//        List<Inventory> inventoryList = getInventories(inventoryStorageVo, list);
//        getDocumentType(inventoryStorageVo.getDocumentType());
//        InventoryListReturnVo inventoryListReturnVo = new InventoryListReturnVo();
//        if (inventoryStorageVo.getQty().compareTo(BigDecimal.ZERO) == 0) {
//            return inventoryListReturnVo;
//        }
//        List<BinIdsVo> binIdsVos = new ArrayList<>();
//        Inventory inventory = new Inventory();
//        if (CollectionUtils.isNotEmpty(inventoryList)) {
//            inventory = inventoryList.get(0);
//        } else {
//            inventory = null;
//        }
//        verification(inventoryStorageVo, inventory == null ? null : inventory.getAuxQty());
//        if (null != inventoryStorageVo.getBinIds()&&inventoryStorageVo.getBinIds().size()>0) {
//            binIdsVos = inventoryStorageVo.getBinIds().entrySet().stream().map(c -> new BinIdsVo(c.getKey(), c.getValue())).collect(Collectors.toList());
//            long sum = binIdsVos.stream().mapToLong(BinIdsVo::getQty).sum();
//            if (QtyIsZeroConfig.isOpen) {
//                if (inventoryStorageVo.getQty().compareTo(BigDecimal.ZERO) == 0) {
//                    return new InventoryListReturnVo();
//                }
//                if (inventoryStorageVo.getQty().longValue() != sum) {
//                    throw new Exception("bindIds 为非空时，所有入位数量合计不等于qty");
//                }
//            } else if (sum <= 0 || inventoryStorageVo.getQty().longValue() != sum) {
//                throw new Exception("bindIds 为非空时，所有入位数量大于0并且合计不等于qty");
//            }
//        }
//        //如果开启库龄配置 添加一条 不处理库位存放
//        if (StockAgeConfig.isOpen) {
//            storageAgeInsert(inventoryStorageVo, inventoryListReturnVo, list2);
//        }
//        if (inventory == null) {
//            //直接copy 添加 处理
//            if (getIsOpenNegativeInventory(inventoryStorageVo.getStockId())) {
//                //如果入库数量是正数 不校验  负数 校验
//                if (inventoryStorageVo.getQty().compareTo(BigDecimal.ZERO) < 0) {
//                    throw new Exception("入库负数不允许");
//                }
//            }
//            inventoryListReturnVo = storageInsert(inventoryStorageVo, inventoryListReturnVo, binIdsVos, list1);
//        } else {
//            inventoryListReturnVo = storageUpdate(inventoryStorageVo, inventoryListReturnVo, inventory, binIdsVos, list1);
//        }
//
//        return inventoryListReturnVo;
//
//    }
//
//    /**
//     * @param inventoryStorageVo    传入的参数
//     * @param inventoryListReturnVo 返回的参数
//     * @param inventory             修改的库存实体
//     * @param binIdsVos             binids 集合
//     * @return
//     * @throws Exception
//     */
//    private InventoryListReturnVo storageUpdate(InventoryStorageVo inventoryStorageVo, InventoryListReturnVo inventoryListReturnVo, Inventory inventory, List<BinIdsVo> binIdsVos, List<InventoryPlacement> list1) throws Exception {
//
//
//        Inventory updateinventory = new Inventory();
//        updateinventory.setId(inventory.getId());
//        updateinventory.setVersion(inventory.getVersion());
//        BigDecimal stockQty = orZero(inventory.getStockQty());
//        BigDecimal lockQty = orZero(inventory.getLockQty());
//        BigDecimal displayQty = orZero(inventory.getDisplayQty());
//        BigDecimal defectQty = orZero(inventory.getDefectQty());
//        BigDecimal wayQty = orZero(inventory.getWayQty());
//        BigDecimal storageQty = orZero(inventory.getStorageQty());
//        BigDecimal rejectLockQty = orZero(inventory.getRejectLockQty());
//        BigDecimal rgetRejectWayQty = orZero(inventory.getRejectWayQty());
//        BigDecimal inspectedQty = orZero(inventory.getInspectedQty());
//        BigDecimal pickingQty = orZero(inventory.getPickingQty());
//        // 库存变动
//        InventoryVariation inventoryVariation = new InventoryVariation();
//        BeanUtils.copyProperties(inventoryStorageVo, inventoryVariation);
//        switch (inventoryStorageVo.getTo().getValue()) {
//            case TargetTypeVo.Normal:
//                stockQty = stockQty.add(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeStockQty(inventoryStorageVo.getQty());
//                updateinventory.setStockQty(stockQty);
//                break;
//            case TargetTypeVo.Lock:
//                stockQty = stockQty.add(inventoryStorageVo.getQty());
//                lockQty = lockQty.add(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeStockQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeLockQty(inventoryStorageVo.getQty());
//                updateinventory.setStockQty(stockQty);
//                updateinventory.setLockQty(lockQty);
//
//                break;
//            case TargetTypeVo.Display:
//                stockQty = stockQty.add(inventoryStorageVo.getQty());
//                displayQty = displayQty.add(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeStockQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeDisplayQty(inventoryStorageVo.getQty());
//                updateinventory.setStockQty(stockQty);
//                updateinventory.setDisplayQty(displayQty);
//
//                break;
//            case TargetTypeVo.Defect:
//                stockQty = stockQty.add(inventoryStorageVo.getQty());
//                defectQty = defectQty.add(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeStockQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeDefectQty(inventoryStorageVo.getQty());
//                updateinventory.setStockQty(stockQty);
//                updateinventory.setDefectQty(defectQty);
//                break;
//            case TargetTypeVo.Way:
//                wayQty = wayQty.add(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeWayQty(inventoryStorageVo.getQty());
//                updateinventory.setWayQty(wayQty);
//                break;
//            case TargetTypeVo.Storage:
//                storageQty = storageQty.add(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeStorageQty(inventoryStorageVo.getQty());
//                updateinventory.setStorageQty(storageQty);
//                break;
//            case TargetTypeVo.RejectLock:
//                rejectLockQty = rejectLockQty.add(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeRejectLockQty(inventoryStorageVo.getQty());
//                updateinventory.setRejectLockQty(rejectLockQty);
//
//                break;
//            case TargetTypeVo.RejectWay:
//                rgetRejectWayQty = rgetRejectWayQty.add(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeRejectWayQty(inventoryStorageVo.getQty());
//                updateinventory.setRejectWayQty(rgetRejectWayQty);
//                break;
//            case TargetTypeVo.Inspected:
//                inspectedQty = inspectedQty.add(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeInspectedQty(inventoryStorageVo.getQty());
//                updateinventory.setInspectedQty(inspectedQty);
//                break;
//            case TargetTypeVo.Picking:
//                pickingQty = pickingQty.add(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeInspectedQty(inventoryStorageVo.getQty());
//                updateinventory.setPickingQty(pickingQty);
//                break;
//            default:
//                throw new Exception("入库目标类型不正确");
//        }
//        if (getIsOpenNegativeInventory(inventoryStorageVo.getStockId())) {
//            validStock(inventory.getItemId(), stockQty, lockQty, displayQty, defectQty, wayQty, storageQty, rejectLockQty, rgetRejectWayQty, inspectedQty);
//        }
//        List<Inventory> updateInventoryList = new ArrayList<>();
//        updateInventoryList.add(updateinventory);
//        inventoryListReturnVo.setUpdateInventoryList(updateInventoryList);
//
//        inventoryVariation.setStockQty(stockQty);
//        inventoryVariation.setLockQty(lockQty);
//        inventoryVariation.setDisplayQty(displayQty);
//        inventoryVariation.setDefectQty(defectQty);
//        inventoryVariation.setWayQty(wayQty);
//        inventoryVariation.setStorageQty(storageQty);
//        inventoryVariation.setRejectLockQty(rejectLockQty);
//        inventoryVariation.setRejectWayQty(rgetRejectWayQty);
//        inventoryVariation.setInspectedQty(inspectedQty);
//
//        inventoryVariation.setChangeType("In");
//        inventoryVariation.setFromType(inventoryStorageVo.getTo().getValue());
//        inventoryVariation.setItemId(inventoryStorageVo.getItem().getId());
//        inventoryVariation.setOperateTime(new Date());
//        // inventoryVariationMapper.insert(inventoryVariation);
//        inventoryListReturnVo.setInventoryVariations(inventoryVariation);
//        if (binIdsVos.size() != 0) {
//            List<InventoryPlacement> addsInventoryPlacement = new ArrayList<>();
//            List<InventoryPlacementVariation> addInventoryPlacementVariation = new ArrayList<>();
//            List<InventoryPlacement> updateList = new ArrayList<>();
//            for (BinIdsVo binIdsVo : binIdsVos) {
//                if (ObjectUtils.isEmpty(binIdsVo.getBinId())) {
//                    if (inventoryStorageVo.getTo().getValue().equals(TargetTypeVo.Defect)) {
//                        //  binIdsVo.setBinId(getSearchByWarehouseBin(inventoryStorageVo.getStockId(),inventoryStorageVo.getShopId(),inventoryStorageVo.getFnSku(),inventoryStorageVo.getItem().getId(),2));
//                    } else {
//                        //  binIdsVo.setBinId(getSearchByWarehouseBin(inventoryStorageVo.getStockId(),inventoryStorageVo.getShopId(),inventoryStorageVo.getFnSku(),inventoryStorageVo.getItem().getId(),1));
//                    }
//                }
//                InventoryPlacementVariation inventoryPlacementVariation = new InventoryPlacementVariation();
//                BeanUtils.copyProperties(inventoryStorageVo, inventoryPlacementVariation);
//                inventoryPlacementVariation.setChangeType("In");
//                inventoryPlacementVariation.setFromType(inventoryStorageVo.getFromBinIdsType().getValue());
//                inventoryPlacementVariation.setItemId(inventoryStorageVo.getItem().getId());
//                inventoryPlacementVariation.setOperateTime(new Date());
//                inventoryPlacementVariation.setBinId(binIdsVo.getBinId());
//                List<InventoryPlacement> inventoryPlacementList = getInventoryPlacementList(inventoryStorageVo, binIdsVo.getBinId(), list1);
//                InventoryPlacement inventoryPlacement = new InventoryPlacement();
//                if (CollectionUtils.isNotEmpty(inventoryPlacementList)) {
//                    inventoryPlacement = inventoryPlacementList.get(0);
//                } else {
//                    inventoryPlacement = null;
//                }
//                if (inventoryPlacement != null) {
//                    getUpdateInvetoryPlacement(inventoryStorageVo, inventoryListReturnVo, binIdsVo, inventoryPlacementVariation, inventoryPlacement, updateList, addInventoryPlacementVariation);
//                } else {
//                    if (new BigDecimal(binIdsVo.getQty()).compareTo(BigDecimal.ZERO) < 0) {
//                        throw new Exception("库存货位放置表库存不足");
//                    }
//                    InventoryPlacement insertInventoryPlacement = new InventoryPlacement();
//                    BeanUtils.copyProperties(inventoryStorageVo, insertInventoryPlacement);
//                    insertInventoryPlacement.setBinId(binIdsVo.getBinId());
//                    insertInventoryPlacement.setAuxId(inventory.getAuxId());
//                    insertInventoryPlacement.setAuxQty(inventory.getAuxQty());
//                    insertInventoryPlacement.setItemId(inventoryStorageVo.getItem().getId());
//                    if (StringUtils.isBlank(inventoryStorageVo.getBatchNo())) {
//                        insertInventoryPlacement.setBatchNo(null);
//                    }
//                    switch (inventoryStorageVo.getFromBinIdsType().getValue()) {
//                        case TargetTypeVo.Normal:
//                            insertInventoryPlacement.setStockQty(new BigDecimal(binIdsVo.getQty()));
//                            insertInventoryPlacement.setLockQty(null);
//                            insertInventoryPlacement.setWayQty(null);
//                            inventoryPlacementVariation.setStockQty(new BigDecimal(binIdsVo.getQty()));
//                            inventoryPlacementVariation.setChangeStockQty(new BigDecimal(binIdsVo.getQty()));
//                            break;
//                        case TargetTypeVo.Lock:
//                            insertInventoryPlacement.setStockQty(null);
//                            insertInventoryPlacement.setLockQty(new BigDecimal(binIdsVo.getQty()));
//                            insertInventoryPlacement.setWayQty(null);
//                            inventoryPlacementVariation.setLockQty(new BigDecimal(binIdsVo.getQty()));
//                            inventoryPlacementVariation.setChangeLockQty(new BigDecimal(binIdsVo.getQty()));
//                            break;
//                        case TargetTypeVo.Way:
//                            insertInventoryPlacement.setStockQty(null);
//                            insertInventoryPlacement.setLockQty(null);
//                            insertInventoryPlacement.setWayQty(new BigDecimal(binIdsVo.getQty()));
//                            inventoryPlacementVariation.setWayQty(new BigDecimal(binIdsVo.getQty()));
//                            inventoryPlacementVariation.setChangeWayQty(new BigDecimal(binIdsVo.getQty()));
//                            break;
//                        default:
//                            throw new Exception("入库位目标类型不正确");
//                    }
//                    addsInventoryPlacement.add(insertInventoryPlacement);
//                    addInventoryPlacementVariation.add(inventoryPlacementVariation);
//                }
//            }
//            if(addsInventoryPlacement.size()>0){
//                inventoryListReturnVo.setInventoryPlacement(addsInventoryPlacement);
//            }
//            inventoryListReturnVo.setInventoryPlacementVariations(addInventoryPlacementVariation);
//
//
//        }
//        return inventoryListReturnVo;
//    }
//
//    /**
//     * @param inventoryStorageVo    传入的参数
//     * @param inventoryListReturnVo 返回的参数
//     * @param binIdsVos             binids 集合
//     * @return
//     * @throws Exception
//     */
//    private InventoryListReturnVo storageInsert(InventoryStorageVo inventoryStorageVo, InventoryListReturnVo inventoryListReturnVo, List<BinIdsVo> binIdsVos, List<InventoryPlacement> list1) throws Exception {
//        Inventory insertInventory = new Inventory();
//        BeanUtils.copyProperties(inventoryStorageVo, insertInventory);
//        if (StringUtils.isBlank(inventoryStorageVo.getBatchNo())) {
//            insertInventory.setBatchNo(null);
//        }
//        InventoryVariation inventoryVariation = new InventoryVariation();
//        BeanUtils.copyProperties(inventoryStorageVo, inventoryVariation);
//        inventoryVariation.setChangeType("In");
//        inventoryVariation.setFromType(inventoryStorageVo.getTo().getValue());
//        inventoryVariation.setItemId(inventoryStorageVo.getItem().getId());
//        inventoryVariation.setOperateTime(new Date());
//        switch (inventoryStorageVo.getTo().getValue()) {
//            case TargetTypeVo.Normal:
//                inventoryVariation.setStockQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeStockQty(inventoryStorageVo.getQty());
//                insertInventory.setStockQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.Lock:
//                inventoryVariation.setLockQty(inventoryStorageVo.getQty());
//                inventoryVariation.setStockQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeLockQty(inventoryStorageVo.getQty());
//                insertInventory.setStockQty(inventoryStorageVo.getQty());
//                insertInventory.setLockQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.Display:
//                inventoryVariation.setDisplayQty(inventoryStorageVo.getQty());
//                inventoryVariation.setStockQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeDisplayQty(inventoryStorageVo.getQty());
//                insertInventory.setStockQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.Defect:
//                inventoryVariation.setDefectQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeDefectQty(inventoryStorageVo.getQty());
//                insertInventory.setStockQty(inventoryStorageVo.getQty());
//                insertInventory.setDefectQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            //        }
//            case TargetTypeVo.Way:
//                inventoryVariation.setWayQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeWayQty(inventoryStorageVo.getQty());
//                insertInventory.setWayQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.Storage:
//                inventoryVariation.setStorageQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeStorageQty(inventoryStorageVo.getQty());
//                insertInventory.setStorageQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                this.save(insertInventory);
//                break;
//            case TargetTypeVo.RejectLock:
//                inventoryVariation.setRejectLockQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeRejectLockQty(inventoryStorageVo.getQty());
//                insertInventory.setRejectLockQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.RejectWay:
//                inventoryVariation.setRejectWayQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeRejectWayQty(inventoryStorageVo.getQty());
//                insertInventory.setRejectWayQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.Inspected:
//                inventoryVariation.setInspectedQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeInspectedQty(inventoryStorageVo.getQty());
//                insertInventory.setInspectedQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.Picking:
//                inventoryVariation.setPickingQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangePickingQty(inventoryStorageVo.getQty());
//                insertInventory.setPickingQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            default:
//                throw new Exception("入库目标类型不正确");
//        }
//        inventoryListReturnVo.setInventory(insertInventory);
//        //处理完 主表添加 库存变动 和村村存放置
//        inventoryListReturnVo.setInventoryVariations(inventoryVariation);
//        if (binIdsVos.size() != 0) {
//            List<InventoryPlacement> addsInventoryPlacement = new ArrayList<>();
//            List<InventoryPlacementVariation> addsInventoryPlacementVariation = new ArrayList<>();
//            List<InventoryPlacement> updateList = new ArrayList<>();
//            for (BinIdsVo binIdsVo : binIdsVos) {
//                InventoryPlacementVariation inventoryPlacementVariation = new InventoryPlacementVariation();
//                BeanUtils.copyProperties(inventoryStorageVo, inventoryPlacementVariation);
//                inventoryPlacementVariation.setChangeType("In");
//                inventoryPlacementVariation.setFromType(inventoryStorageVo.getFromBinIdsType().getValue());
//                inventoryPlacementVariation.setItemId(inventoryStorageVo.getItem().getId());
//                inventoryPlacementVariation.setOperateTime(new Date());
//                inventoryPlacementVariation.setBinId(binIdsVo.getBinId());
//                List<InventoryPlacement> inventoryPlacementList = getInventoryPlacementList(inventoryStorageVo, binIdsVo.getBinId(), list1);
//                InventoryPlacement inventoryPlacement = new InventoryPlacement();
//                if (CollectionUtils.isNotEmpty(inventoryPlacementList)) {
//                    inventoryPlacement = inventoryPlacementList.get(0);
//                } else {
//                    inventoryPlacement = null;
//                }
//                if (inventoryPlacement != null) {
//                    getUpdateInvetoryPlacement(inventoryStorageVo, inventoryListReturnVo, binIdsVo, inventoryPlacementVariation, inventoryPlacement, updateList, addsInventoryPlacementVariation);
//                } else {
//                    InventoryPlacement insertInventoryPlacement = new InventoryPlacement();
//                    BeanUtils.copyProperties(inventoryStorageVo, insertInventoryPlacement);
//                    insertInventoryPlacement.setBinId(binIdsVo.getBinId());
//                    //insertInventoryPlacement.setStockQty(new BigDecimal(binIdsVo.getQty()));
//                    insertInventoryPlacement.setAuxId(insertInventory.getAuxId());
//                    insertInventoryPlacement.setAuxQty(insertInventory.getAuxQty());
//                    insertInventoryPlacement.setItemId(inventoryStorageVo.getItem().getId());
//                    if (StringUtils.isBlank(inventoryStorageVo.getBatchNo())) {
//                        insertInventoryPlacement.setBatchNo(null);
//                    }
//                    switch (inventoryStorageVo.getFromBinIdsType().getValue()) {
//                        case TargetTypeVo.Normal:
//                            inventoryPlacementVariation.setStockQty(new BigDecimal(binIdsVo.getQty()));
//                            inventoryPlacementVariation.setChangeStockQty(new BigDecimal(binIdsVo.getQty()));
//                            insertInventoryPlacement.setStockQty(new BigDecimal(binIdsVo.getQty()));
//                            insertInventoryPlacement.setLockQty(null);
//                            insertInventoryPlacement.setWayQty(null);
//                            break;
//                        case TargetTypeVo.Way:
//                            inventoryPlacementVariation.setWayQty(new BigDecimal(binIdsVo.getQty()));
//                            inventoryPlacementVariation.setChangeWayQty(new BigDecimal(binIdsVo.getQty()));
//                            insertInventoryPlacement.setWayQty(new BigDecimal(binIdsVo.getQty()));
//                            insertInventoryPlacement.setStockQty(null);
//                            insertInventoryPlacement.setLockQty(null);
//                            break;
//                        case TargetTypeVo.Lock:
//                            inventoryPlacementVariation.setLockQty(new BigDecimal(binIdsVo.getQty()));
//                            inventoryPlacementVariation.setChangeLockQty(new BigDecimal(binIdsVo.getQty()));
//                            insertInventoryPlacement.setLockQty(new BigDecimal(binIdsVo.getQty()));
//                            insertInventoryPlacement.setStockQty(null);
//                            insertInventoryPlacement.setWayQty(null);
//                            break;
//                        default:
//                            throw new Exception("入库位目标类型不正确");
//                    }
//                    addsInventoryPlacement.add(insertInventoryPlacement);
//                    addsInventoryPlacementVariation.add(inventoryPlacementVariation);
//                }
//                if(addsInventoryPlacement.size()>0){
//                    inventoryListReturnVo.setInventoryPlacement(addsInventoryPlacement);
//                }
//                inventoryListReturnVo.setInventoryPlacementVariations(addsInventoryPlacementVariation);
//
//            }
//        }
//        return inventoryListReturnVo;
//    }
//
//    private void validStock(Long itemId, BigDecimal stockQty, BigDecimal lockQty, BigDecimal displayQty, BigDecimal defectQty, BigDecimal wayQty, BigDecimal storageQty, BigDecimal rejectLockQty, BigDecimal rgetRejectWayQty, BigDecimal inspectedQty) throws Exception {
//
//        if (stockQty.compareTo(BigDecimal.ZERO) < 0) {
//            throw new Exception(getItemIdName(itemId) + " 总库存不能小于 0");
//        }
//        if (lockQty.compareTo(BigDecimal.ZERO) < 0) {
//            throw new Exception(getItemIdName(itemId) + " 锁定库存不能小于 0");
//        }
//        if (displayQty.compareTo(BigDecimal.ZERO) < 0) {
//            throw new Exception(getItemIdName(itemId) + " 展示库存不能小于 0");
//        }
//        if (defectQty.compareTo(BigDecimal.ZERO) < 0) {
//            throw new Exception(getItemIdName(itemId) + " 残次库存不能小于 0");
//        }
//        if (lockQty.add(displayQty).add(defectQty).compareTo(stockQty) > 0) {
//            throw new Exception(getItemIdName(itemId) + " 锁定库存加展示库存加残次库存不能大于总库存");
//        }
//        if (wayQty.compareTo(BigDecimal.ZERO) < 0) {
//            throw new Exception(getItemIdName(itemId) + " 在途库存不能小于 0");
//        }
//        if (storageQty.compareTo(BigDecimal.ZERO) < 0) {
//            throw new Exception(getItemIdName(itemId) + " 暂存库存不能小于 0");
//        }
//        if (rejectLockQty.compareTo(BigDecimal.ZERO) < 0) {
//            throw new Exception(getItemIdName(itemId) + " 次品锁定库存不能小于 0");
//        }
//        if (rgetRejectWayQty.compareTo(BigDecimal.ZERO) < 0) {
//            throw new Exception(getItemIdName(itemId) + " 次品在途库存不能小于 0");
//        }
//        if (inspectedQty.compareTo(BigDecimal.ZERO) < 0) {
//            throw new Exception(getItemIdName(itemId) + " 待检库存不能小于 0");
//        }
//
//    }
//
//    /**
//     * 修改
//     *
//     * @param inventoryStorageVo
//     * @param inventoryListReturnVo
//     * @param binIdsVo
//     * @param inventoryPlacementVariation
//     * @param inventoryPlacement
//     * @throws Exception
//     */
//
//    private void getUpdateInvetoryPlacement(InventoryStorageVo inventoryStorageVo, InventoryListReturnVo inventoryListReturnVo, BinIdsVo binIdsVo, InventoryPlacementVariation inventoryPlacementVariation, InventoryPlacement inventoryPlacement, List<InventoryPlacement> updateList, List<InventoryPlacementVariation> addsInventoryPlacementVariation) throws Exception {
//        InventoryPlacement update = new InventoryPlacement();
//        update.setId(inventoryPlacement.getId());
//        update.setVersion(inventoryPlacement.getVersion());
//        switch (inventoryStorageVo.getFromBinIdsType().getValue()) {
//            case TargetTypeVo.Normal:
//                inventoryPlacementVariation.setStockQty(orZero(inventoryPlacement.getStockQty()).add(new BigDecimal(binIdsVo.getQty())));
//                if (inventoryPlacementVariation.getStockQty().compareTo(BigDecimal.ZERO) < 0) {
//                    throw new Exception("库存货位放置表在可用库存不足");
//                }
//                inventoryPlacementVariation.setChangeStockQty(new BigDecimal(binIdsVo.getQty()));
//                if (inventoryPlacement.getStockQty() != null) {
//                    update.setStockQty(inventoryPlacement.getStockQty().add(new BigDecimal(binIdsVo.getQty())));
//                } else {
//                    update.setStockQty(new BigDecimal(binIdsVo.getQty()));
//                }
//                break;
//            case TargetTypeVo.Lock:
//                inventoryPlacementVariation.setLockQty(orZero(inventoryPlacement.getLockQty()).add(new BigDecimal(binIdsVo.getQty())));
//                if (inventoryPlacementVariation.getLockQty().compareTo(BigDecimal.ZERO) < 0) {
//                    throw new Exception("库存货位放置表在锁定库存不足");
//                }
//                inventoryPlacementVariation.setChangeLockQty(new BigDecimal(binIdsVo.getQty()));
//                if (inventoryPlacement.getLockQty() != null) {
//                    update.setLockQty(inventoryPlacement.getLockQty().add(new BigDecimal(binIdsVo.getQty())));
//                } else {
//                    update.setLockQty(new BigDecimal(binIdsVo.getQty()));
//                }
//
//                break;
//            case TargetTypeVo.Way:
//                if (inventoryPlacementVariation.getWayQty().compareTo(BigDecimal.ZERO) < 0) {
//                    throw new Exception("库存货位放置表在途库存不足");
//                }
//                inventoryPlacementVariation.setChangeWayQty(new BigDecimal(binIdsVo.getQty()));
//                if (inventoryPlacement.getWayQty() != null) {
//                    update.setWayQty(inventoryPlacement.getWayQty().add(new BigDecimal(binIdsVo.getQty())));
//                    ;
//                } else {
//                    update.setWayQty(new BigDecimal(binIdsVo.getQty()));
//                    ;
//                }
//
//                break;
//            default:
//                throw new Exception("入库位目标类型不正确");
//        }
//        updateList.add(update);
//        inventoryListReturnVo.setUpdateInventoryPlacementList(updateList);
//        addsInventoryPlacementVariation.add(inventoryPlacementVariation);
//    }
//
//    private List<InventoryPlacement> getInventoryPlacementList(InventoryStorageVo inventoryStorageVo, Long binId, List<InventoryPlacement> list1) {
//        list1 = list1.stream().filter(s -> s.getItemId().equals(inventoryStorageVo.getItem().getId()) && s.getBinId().equals(binId)).collect(Collectors.toList());
//        if (inventoryStorageVo.getBatchNo() == null) {
//            list1 = list1.stream().filter(s -> s.getBatchNo() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getBatchNo() != null).filter(s -> s.getBatchNo().equals(inventoryStorageVo.getBatchNo())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getStockId() == null) {
//            list1 = list1.stream().filter(s -> s.getStockId() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getStockId() != null).filter(s -> s.getStockId().equals(inventoryStorageVo.getStockId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getFnSku() == null) {
//            list1 = list1.stream().filter(s -> s.getFnSku() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getFnSku() != null).filter(s -> s.getFnSku().equals(inventoryStorageVo.getFnSku())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getShopId() == null) {
//            list1 = list1.stream().filter(s -> s.getShopId() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getShopId() != null).filter(s -> s.getShopId().equals(inventoryStorageVo.getShopId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getExpiryDate() == null) {
//            list1 = list1.stream().filter(s -> s.getExpiryDate() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getExpiryDate() != null).filter(s -> s.getExpiryDate().equals(inventoryStorageVo.getExpiryDate())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getProjectId() == null) {
//            list1 = list1.stream().filter(s -> s.getProjectId() == null).collect(Collectors.toList());
//        } else {
//            list1 = list1.stream().filter(s -> s.getProjectId() != null).filter(s -> s.getProjectId().equals(inventoryStorageVo.getProjectId())).collect(Collectors.toList());
//        }
//        return list1;
//
//    }
//
//    private InventoryListReturnVo storageAgeInsert(InventoryStorageVo inventoryStorageVo, InventoryListReturnVo inventoryListReturnVo, List<InventoryBatchNo> inventoryBatchNoList) throws Exception {
//        if (inventoryStorageVo.getQty().compareTo(BigDecimal.ZERO) < 0) {
//            InventoryOutboundVo model = new InventoryOutboundVo();
//            BeanUtils.copyProperties(inventoryStorageVo, model);
//            model.setQty(model.getQty().negate());
//            model.setModel(PatternEnum.FIFO);
//            model.setFrom(inventoryStorageVo.getTo());
//            // List<InventoryBatchNo> list= inventoryBatchNoMapper.selectByOutboundList(model,model.getModel().getValue());
//
//            List<InventoryBatchNo> list = getInventoryBatchNos(inventoryStorageVo, inventoryBatchNoList);
//            if (CollectionUtils.isEmpty(list)) {
//                // 是否开启负库存 如果开启
//                if (getIsOpenNegativeInventory(inventoryStorageVo.getStockId())) {
//                    throw new Exception(getItemIdName(inventoryStorageVo.getItem().getId()) + " 没有查到对应批次库存表数据");
//                }
//            }
//            // 是否开启负库存
//            if (getIsOpenNegativeInventory(model.getStockId())) {
//                verificationOutboundInventoryBatchNo(model, list);
//            }
//            inventoryListReturnVo.setUpdateInventoryBatchNoList(outboundUpdateBatchNo(model, list));
//            return inventoryListReturnVo;
//        }
//        InventoryBatchNo insertInventory = new InventoryBatchNo();
//        BeanUtils.copyProperties(inventoryStorageVo, insertInventory);
//        if (StringUtils.isBlank(inventoryStorageVo.getBatchNo())) {
//            insertInventory.setBatchNo(null);
//        }
//        insertInventory.setStockAgeBatchNo(createBatchNo());
//        InventoryVariation inventoryVariation = new InventoryVariation();
//        BeanUtils.copyProperties(inventoryStorageVo, inventoryVariation);
//        inventoryVariation.setChangeType("In");
//        inventoryVariation.setFromType(inventoryStorageVo.getTo().getValue());
//        inventoryVariation.setItemId(inventoryStorageVo.getItem().getId());
//        inventoryVariation.setOperateTime(new Date());
//        switch (inventoryStorageVo.getTo().getValue()) {
//            case TargetTypeVo.Normal:
//                inventoryVariation.setStockQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeStockQty(inventoryStorageVo.getQty());
//                insertInventory.setStockQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.Lock:
//                inventoryVariation.setLockQty(inventoryStorageVo.getQty());
//                inventoryVariation.setStockQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeLockQty(inventoryStorageVo.getQty());
//                insertInventory.setStockQty(inventoryStorageVo.getQty());
//                insertInventory.setLockQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.Display:
//                inventoryVariation.setDisplayQty(inventoryStorageVo.getQty());
//                inventoryVariation.setStockQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeDisplayQty(inventoryStorageVo.getQty());
//                insertInventory.setStockQty(inventoryStorageVo.getQty());
//                insertInventory.setDisplayQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.Defect:
//                inventoryVariation.setDefectQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeDefectQty(inventoryStorageVo.getQty());
//                insertInventory.setStockQty(inventoryStorageVo.getQty());
//                insertInventory.setDefectQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.Way:
//                inventoryVariation.setWayQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeWayQty(inventoryStorageVo.getQty());
//                insertInventory.setWayQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.Storage:
//                inventoryVariation.setStorageQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeStorageQty(inventoryStorageVo.getQty());
//                insertInventory.setStorageQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.RejectLock:
//                inventoryVariation.setRejectLockQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeStorageQty(inventoryStorageVo.getQty());
//                insertInventory.setRejectLockQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.RejectWay:
//                inventoryVariation.setRejectWayQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeRejectWayQty(inventoryStorageVo.getQty());
//                insertInventory.setRejectWayQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.Inspected:
//                inventoryVariation.setInspectedQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangeInspectedQty(inventoryStorageVo.getQty());
//                insertInventory.setInspectedQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            case TargetTypeVo.Picking:
//                inventoryVariation.setPickingQty(inventoryStorageVo.getQty());
//                inventoryVariation.setChangePickingQty(inventoryStorageVo.getQty());
//                insertInventory.setPickingQty(inventoryStorageVo.getQty());
//                insertInventory.setItemId(inventoryStorageVo.getItem().getId());
//                break;
//            default:
//                throw new Exception("入库目标类型不正确");
//        }
//        inventoryListReturnVo.setInventoryBatchNo(insertInventory);
//        return inventoryListReturnVo;
//    }
//
//    private List<InventoryBatchNo> outboundUpdateBatchNo(InventoryOutboundVo model, List<InventoryBatchNo> list) throws Exception {
//        {
//            List<InventoryBatchNo> updateList = new ArrayList<>();
//            // 要处理的量
//            BigDecimal qtySum = model.getQty();
//            List<Long> updateIds = new ArrayList<>();
//            List<Long> delIds = new ArrayList<>();
//            List<Long> variationIds = new ArrayList<>();
//            for (InventoryBatchNo inventory : list) {
//                if (qtySum.compareTo(BigDecimal.ZERO) == 0) {
//                    //库存都处理完
//                    break;
//                }
//                InventoryVariation inventoryVariation = new InventoryVariation();
//
//
//                InventoryBatchNo updateInventory = new InventoryBatchNo();
//                updateInventory.setId(inventory.getId());
//                updateInventory.setVersion(inventory.getVersion());
//                BigDecimal stockQty = orZero(inventory.getStockQty());
//                BigDecimal lockQty = orZero(inventory.getLockQty());
//                BigDecimal detDefectQty = orZero(inventory.getDefectQty());
//                BigDecimal wayQty = orZero(inventory.getWayQty());
//                BigDecimal displayQty = orZero(inventory.getDisplayQty());
//                BigDecimal normalQty = stockQty.subtract(lockQty).subtract(detDefectQty).subtract(displayQty);
//                BigDecimal storageQty = orZero(inventory.getStorageQty());
//                BigDecimal rejectLockQty = orZero(inventory.getRejectLockQty());
//                BigDecimal rejectWayQty = orZero(inventory.getRejectWayQty());
//                BigDecimal inspectedQty = orZero(inventory.getInspectedQty());
//                BigDecimal pickingQty = orZero(inventory.getPickingQty());
//                switch (model.getFrom().getValue()) {
//                    case TargetTypeVo.Normal:
//                        if (!getIsOpenNegativeInventory(model.getStockId())) {
//                            updateInventory.setStockQty(stockQty.subtract(qtySum));
//                            inventoryVariation.setStockQty(updateInventory.getStockQty());
//                            inventoryVariation.setChangeStockQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (normalQty.compareTo(qtySum) >= 0) {
//                            updateInventory.setStockQty(stockQty.subtract(qtySum));
//                            inventoryVariation.setStockQty(updateInventory.getStockQty());
//                            inventoryVariation.setChangeStockQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            updateInventory.setStockQty(stockQty.subtract(normalQty));
//                            inventoryVariation.setStockQty(updateInventory.getStockQty());
//                            inventoryVariation.setChangeStockQty(updateInventory.getStockQty().negate());
//                            qtySum = qtySum.subtract(normalQty);
//                        }
//
//                        break;
//                    case TargetTypeVo.Lock:
//                        if (!getIsOpenNegativeInventory(model.getStockId())) {
//                            updateInventory.setStockQty(stockQty.subtract(qtySum));
//                            updateInventory.setLockQty(lockQty.subtract(qtySum));
//                            inventoryVariation.setStockQty(updateInventory.getStockQty());
//                            inventoryVariation.setLockQty(updateInventory.getLockQty());
//                            inventoryVariation.setChangeLockQty(qtySum.negate());
//                            inventoryVariation.setChangeStockQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (lockQty.compareTo(qtySum) >= 0) {
//                            updateInventory.setStockQty(stockQty.subtract(qtySum));
//                            updateInventory.setLockQty(lockQty.subtract(qtySum));
//                            inventoryVariation.setStockQty(updateInventory.getStockQty());
//                            inventoryVariation.setLockQty(updateInventory.getLockQty());
//                            inventoryVariation.setChangeLockQty(qtySum.negate());
//                            inventoryVariation.setChangeStockQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            updateInventory.setStockQty(stockQty.subtract(lockQty));
//                            updateInventory.setLockQty(BigDecimal.ZERO);
//                            inventoryVariation.setLockQty(updateInventory.getLockQty());
//                            inventoryVariation.setStockQty(updateInventory.getStockQty());
//                            inventoryVariation.setChangeLockQty(lockQty.negate());
//                            inventoryVariation.setChangeStockQty(lockQty.negate());
//                            qtySum = qtySum.subtract(lockQty);
//                        }
//
//                        break;
//                    case TargetTypeVo.Display:
//
//                        if (!getIsOpenNegativeInventory(model.getStockId())) {
//                            updateInventory.setStockQty(stockQty.subtract(qtySum));
//                            updateInventory.setDisplayQty(displayQty.subtract(qtySum));
//                            inventoryVariation.setDisplayQty(updateInventory.getDisplayQty());
//                            inventoryVariation.setStockQty(updateInventory.getStockQty());
//                            inventoryVariation.setChangeDisplayQty(qtySum.negate());
//                            inventoryVariation.setChangeStockQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (displayQty.compareTo(qtySum) >= 0) {
//                            updateInventory.setStockQty(stockQty.subtract(qtySum));
//                            updateInventory.setDisplayQty(displayQty.subtract(qtySum));
//                            inventoryVariation.setDisplayQty(updateInventory.getDisplayQty());
//                            inventoryVariation.setStockQty(updateInventory.getStockQty());
//                            inventoryVariation.setChangeDisplayQty(qtySum.negate());
//                            inventoryVariation.setChangeStockQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            updateInventory.setLockQty(BigDecimal.ZERO);
//                            updateInventory.setStockQty(stockQty.subtract(displayQty));
//                            inventoryVariation.setLockQty(updateInventory.getLockQty());
//                            inventoryVariation.setStockQty(updateInventory.getStockQty());
//                            inventoryVariation.setChangeLockQty(displayQty.negate());
//                            inventoryVariation.setChangeStockQty(displayQty.negate());
//                            qtySum = qtySum.subtract(displayQty);
//                        }
//
//                        break;
//                    case TargetTypeVo.Defect:
//
//                        if (!getIsOpenNegativeInventory(model.getStockId())) {
//                            updateInventory.setStockQty(stockQty.subtract(qtySum));
//                            updateInventory.setDefectQty(detDefectQty.subtract(qtySum));
//                            inventoryVariation.setStockQty(updateInventory.getStockQty());
//                            inventoryVariation.setDefectQty(updateInventory.getDefectQty());
//                            inventoryVariation.setChangeStockQty(qtySum.negate());
//                            inventoryVariation.setChangeDefectQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (detDefectQty.compareTo(qtySum) >= 0) {
//                            updateInventory.setStockQty(stockQty.subtract(qtySum));
//                            updateInventory.setDefectQty(detDefectQty.subtract(qtySum));
//                            inventoryVariation.setStockQty(updateInventory.getStockQty());
//                            inventoryVariation.setDefectQty(updateInventory.getDefectQty());
//                            inventoryVariation.setChangeStockQty(qtySum.negate());
//                            inventoryVariation.setChangeDefectQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            updateInventory.setStockQty(stockQty.subtract(detDefectQty));
//                            updateInventory.setDefectQty(BigDecimal.ZERO);
//                            inventoryVariation.setStockQty(updateInventory.getStockQty());
//                            inventoryVariation.setDefectQty(updateInventory.getDefectQty());
//                            inventoryVariation.setChangeStockQty(detDefectQty.negate());
//                            inventoryVariation.setDefectQty(detDefectQty.negate());
//                            qtySum = qtySum.subtract(detDefectQty);
//                        }
//                        break;
//                    case TargetTypeVo.Way:
//                        if (!getIsOpenNegativeInventory(model.getStockId())) {
//                            updateInventory.setWayQty(wayQty.subtract(qtySum));
//                            inventoryVariation.setWayQty(updateInventory.getWayQty());
//                            inventoryVariation.setChangeWayQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (wayQty.compareTo(qtySum) >= 0) {
//                            updateInventory.setWayQty(wayQty.subtract(qtySum));
//                            inventoryVariation.setWayQty(updateInventory.getWayQty());
//                            inventoryVariation.setChangeWayQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            updateInventory.setWayQty(BigDecimal.ZERO);
//                            inventoryVariation.setWayQty(updateInventory.getWayQty());
//                            inventoryVariation.setChangeWayQty(wayQty.negate());
//                            qtySum = qtySum.subtract(wayQty);
//                        }
//
//                        break;
//                    case TargetTypeVo.Storage:
//                        if (!getIsOpenNegativeInventory(model.getStockId())) {
//                            updateInventory.setStorageQty(storageQty.subtract(qtySum));
//                            inventoryVariation.setStorageQty(updateInventory.getStorageQty());
//                            inventoryVariation.setChangeStorageQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (storageQty.compareTo(qtySum) >= 0) {
//                            updateInventory.setStorageQty(storageQty.subtract(qtySum));
//                            inventoryVariation.setStorageQty(updateInventory.getStorageQty());
//                            inventoryVariation.setChangeStorageQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            updateInventory.setStorageQty(BigDecimal.ZERO);
//                            inventoryVariation.setStorageQty(updateInventory.getStorageQty());
//                            inventoryVariation.setChangeStorageQty(storageQty.negate());
//                            qtySum = qtySum.subtract(storageQty);
//                        }
//
//                        break;
//                    case TargetTypeVo.RejectLock:
//                        if (!getIsOpenNegativeInventory(model.getStockId())) {
//                            updateInventory.setRejectLockQty(rejectLockQty.subtract(qtySum));
//                            inventoryVariation.setRejectLockQty(updateInventory.getRejectLockQty());
//                            inventoryVariation.setChangeRejectLockQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (rejectLockQty.compareTo(qtySum) >= 0) {
//                            updateInventory.setRejectLockQty(rejectLockQty.subtract(qtySum));
//                            inventoryVariation.setRejectLockQty(updateInventory.getRejectLockQty());
//                            inventoryVariation.setChangeRejectLockQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            updateInventory.setRejectLockQty(BigDecimal.ZERO);
//                            inventoryVariation.setRejectLockQty(updateInventory.getRejectLockQty());
//                            inventoryVariation.setChangeRejectLockQty(rejectLockQty.negate());
//                            qtySum = qtySum.subtract(rejectLockQty);
//                        }
//
//                        break;
//                    case TargetTypeVo.RejectWay:
//                        if (!getIsOpenNegativeInventory(model.getStockId())) {
//                            updateInventory.setRejectWayQty(rejectWayQty.subtract(qtySum));
//                            inventoryVariation.setRejectWayQty(updateInventory.getRejectWayQty());
//                            inventoryVariation.setChangeRejectWayQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (rejectWayQty.compareTo(qtySum) >= 0) {
//                            updateInventory.setRejectWayQty(rejectWayQty.subtract(qtySum));
//                            inventoryVariation.setRejectWayQty(updateInventory.getRejectWayQty());
//                            inventoryVariation.setChangeRejectWayQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            updateInventory.setRejectWayQty(BigDecimal.ZERO);
//                            inventoryVariation.setRejectWayQty(updateInventory.getRejectWayQty());
//                            inventoryVariation.setChangeRejectWayQty(rejectWayQty.negate());
//                            qtySum = qtySum.subtract(rejectWayQty);
//                        }
//
//                        break;
//                    case TargetTypeVo.Inspected:
//                        if (!getIsOpenNegativeInventory(model.getStockId())) {
//                            updateInventory.setInspectedQty(inspectedQty.subtract(qtySum));
//                            inventoryVariation.setInspectedQty(updateInventory.getInspectedQty());
//                            inventoryVariation.setChangeInspectedQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (inspectedQty.compareTo(qtySum) >= 0) {
//                            updateInventory.setInspectedQty(inspectedQty.subtract(qtySum));
//                            inventoryVariation.setInspectedQty(updateInventory.getInspectedQty());
//                            inventoryVariation.setChangeInspectedQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            updateInventory.setInspectedQty(BigDecimal.ZERO);
//                            inventoryVariation.setInspectedQty(updateInventory.getInspectedQty());
//                            inventoryVariation.setChangeInspectedQty(inspectedQty.negate());
//                            qtySum = qtySum.subtract(inspectedQty);
//                        }
//
//                        break;
//                    case TargetTypeVo.Picking:
//                        if (!getIsOpenNegativeInventory(model.getStockId())) {
//                            updateInventory.setPickingQty(pickingQty.subtract(qtySum));
//                            inventoryVariation.setPickingQty(updateInventory.getPickingQty());
//                            inventoryVariation.setChangePickingQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else if (pickingQty.compareTo(qtySum) >= 0) {
//                            updateInventory.setPickingQty(pickingQty.subtract(qtySum));
//                            inventoryVariation.setPickingQty(updateInventory.getPickingQty());
//                            inventoryVariation.setChangePickingQty(qtySum.negate());
//                            qtySum = BigDecimal.ZERO;
//                        } else {
//                            updateInventory.setPickingQty(BigDecimal.ZERO);
//                            inventoryVariation.setPickingQty(updateInventory.getPickingQty());
//                            inventoryVariation.setChangePickingQty(pickingQty.negate());
//                            qtySum = qtySum.subtract(pickingQty);
//                        }
//                        break;
//                    default:
//                        throw new Exception("出库源类型不明确");
//                }
//
//                updateList.add(updateInventory);
//            }
//            return updateList;
//        }
//    }
//
//    private static BigDecimal orZero(BigDecimal decimal) {
//        if (decimal == null) {
//            return BigDecimal.ZERO;
//        }
//        return decimal;
//    }
//
//    private String getItemIdName(Long itemId) {
//        String itemIdName = "";
//        if (StringUtils.isNotBlank(MaterialConfig.sql)) {
//            try {
//                String sql = String.format(MaterialConfig.sql, itemId);
//                itemIdName = inventoryMapper.selectMaterial(sql);
//                if(StringUtils.isNotEmpty(itemIdName)){
//                    return itemIdName;
//                }
//                return "";
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//        return itemIdName;
//    }
//
//    private List<InventoryBatchNo> getInventoryBatchNos(InventoryStorageVo inventoryStorageVo, List<InventoryBatchNo> inventoryList) {
//        inventoryList = inventoryList.stream().filter(s -> s.getItemId().equals(inventoryStorageVo.getItem().getId())).collect(Collectors.toList());
//        if (inventoryStorageVo.getBatchNo() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getBatchNo() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getBatchNo() != null).filter(s -> s.getBatchNo() != null).filter(s -> s.getBatchNo().equals(inventoryStorageVo.getBatchNo())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getStockId() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getStockId() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getStockId() != null).filter(s -> s.getStockId() != null).filter(s -> s.getStockId().equals(inventoryStorageVo.getStockId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getFnSku() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getFnSku() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getFnSku() != null).filter(s -> s.getFnSku()!= null).filter(s -> s.getFnSku().equals(inventoryStorageVo.getFnSku())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getShopId() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getShopId() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getShopId() != null).filter(s -> s.getShopId() != null).filter(s -> s.getShopId().equals(inventoryStorageVo.getShopId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getExpiryDate() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getExpiryDate() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getExpiryDate() != null).filter(s -> s.getExpiryDate() != null).filter(s -> s.getExpiryDate().equals(inventoryStorageVo.getExpiryDate())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getProjectId() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getProjectId() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getProjectId() != null).filter(s -> s.getProjectId() != null).filter(s -> s.getProjectId().equals(inventoryStorageVo.getProjectId())).collect(Collectors.toList());
//        }
//        return inventoryList;
//    }
//
//    private void verificationOutboundInventoryBatchNo(InventoryOutboundVo model, List<InventoryBatchNo> inventoryList) throws Exception {
//        //校验库存是否有那么多
//        BigDecimal stockQty = inventoryList.stream().filter(c -> c.getStockQty() != null).map(InventoryBatchNo::getStockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal lockQty = inventoryList.stream().filter(c -> c.getLockQty() != null).map(InventoryBatchNo::getLockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal detDefectQty = inventoryList.stream().filter(c -> c.getDefectQty() != null).map(InventoryBatchNo::getDefectQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal displayQty = inventoryList.stream().filter(c -> c.getDisplayQty() != null).map(InventoryBatchNo::getDisplayQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal wayQty = inventoryList.stream().filter(c -> c.getWayQty() != null).map(InventoryBatchNo::getWayQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal storageQty = inventoryList.stream().filter(c -> c.getStorageQty() != null).map(InventoryBatchNo::getStorageQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal rejectLockQty = inventoryList.stream().filter(c -> c.getRejectLockQty() != null).map(InventoryBatchNo::getRejectLockQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal rejectWayQty = inventoryList.stream().filter(c -> c.getRejectWayQty() != null).map(InventoryBatchNo::getRejectWayQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal inspectedQty = inventoryList.stream().filter(c -> c.getInspectedQty() != null).map(InventoryBatchNo::getInspectedQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//        BigDecimal pickingQty = inventoryList.stream().filter(c -> c.getPickingQty() != null).map(InventoryBatchNo::getPickingQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//
//        switch (model.getFrom().getValue()) {
//            case TargetTypeVo.Normal:
//                //减去 对应的锁库 残次 的 不能大于当前的库存
//                BigDecimal qty = stockQty.subtract(lockQty.add(detDefectQty).add(displayQty));
//                if (qty.compareTo(model.getQty()) < 0) {
//                    // throw new InventoryException(model.getItem().getId(), itemIdName+" 出库数量大于库存数量-锁库数量-残次数量 库存数："+stockQty.subtract(lockQty.add(detDefectQty)));
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + "  库存不足：" + model.getQty().subtract(qty));
//                }
//                break;
//            case TargetTypeVo.Lock:
//                if (lockQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 锁库库存不足：" + model.getQty().subtract(lockQty));
//                }
//                break;
//            case TargetTypeVo.Display:
//                if (displayQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 展品库存不足：" + model.getQty().subtract(displayQty));
//                }
//                break;
//            case TargetTypeVo.Defect:
//                if (detDefectQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 残次库存不足：" + model.getQty().subtract(detDefectQty));
//                }
//                break;
//            case TargetTypeVo.Way:
//                if (wayQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 在途库存不足：" + model.getQty().subtract(wayQty));
//                }
//                break;
//            case TargetTypeVo.Storage:
//                if (storageQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 暂存库存不足：" + model.getQty().subtract(storageQty));
//                }
//                break;
//            case TargetTypeVo.RejectLock:
//                if (rejectLockQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 次品锁定库存不足：" + model.getQty().subtract(rejectLockQty));
//                }
//                break;
//            case TargetTypeVo.RejectWay:
//                if (rejectWayQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 次品在途库存不足：" + model.getQty().subtract(rejectWayQty));
//                }
//                break;
//            case TargetTypeVo.Inspected:
//                if (inspectedQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 待检库存不足：" + model.getQty().subtract(inspectedQty));
//                }
//                break;
//            case TargetTypeVo.Picking:
//                if (pickingQty.compareTo(model.getQty()) < 0) {
//                    throw new InventoryException(model.getItem().getId(), getItemIdName(model.getItem().getId()) + " 拣货库存不足：" + model.getQty().subtract(pickingQty));
//                }
//                break;
//            default:
//                throw new Exception("出库源类型不明确");
//        }
//    }
//
//    /**
//     * 根据当前时间生成分配批次号
//     *
//     * @return
//     */
//    private static String createBatchNo() {
//        // 批次号第一部分：时间
//        DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
//        String currentTimeStr = dateFormat.format(new Date());
//
//        // 批次号第二部分：随机数
//        Random random = new Random();
//        Integer cusCode = random.nextInt(900000) + 100000;
//        String cusCodeStr = cusCode.toString();
//
//        // 返回分配批次
//        return currentTimeStr + cusCodeStr;
//    }
//
//    /**
//     * @param inventoryListVo 校验
//     * @throws Exception
//     */
//    private void verification(InventoryStorageVo inventoryListVo, BigDecimal auxQty) throws Exception {
//        if (null == inventoryListVo.getStockId()) {
//            throw new Exception("stockId 为空");
//        }
//        if (ObjectUtils.allNull(inventoryListVo.getItem())) {
//            throw new Exception("item 为空");
//
//        }
//        if (Boolean.TRUE.equals(inventoryListVo.getItem().getBatchManagement()) && StringUtils.isBlank(inventoryListVo.getBatchNo())) {
//            throw new Exception("item.batchManagement == true 时 batchNo 为空");
//        }
//        if (Boolean.TRUE.equals(inventoryListVo.getItem().getShelfLifeManagement()) && null == inventoryListVo.getShelfLife()
//                && null == inventoryListVo.getProductionDate() && null == inventoryListVo.getExpiryDate()
//        ) {
//            throw new Exception("item.shelfLifeManagement == true 时 shelfLife, productionDate 或 expiryDate 为空");
//        }
//        if (Boolean.TRUE.equals(inventoryListVo.getItem().getAuxiliaryMetering())) {
//            if (inventoryListVo.getItem().getAuxId() == null || auxQty == null) {
//                //主表的字段？？？
//                throw new Exception("auxId 或 auxQty 为空");
//            }
//        }
//        if (QtyIsZeroConfig.isOpen) {
//            if (inventoryListVo.getQty() == null) {
//                throw new Exception("操作数量不能为空");
//            }
//        } else if (inventoryListVo.getQty() == null || BigDecimal.ZERO.equals(inventoryListVo.getQty())) {
//            throw new Exception("操作数量不能为空或零");
//        }
//        if (!Boolean.TRUE.equals(inventoryListVo.getSupportNegative()) && inventoryListVo.getQty().compareTo(BigDecimal.ZERO) < 0) {
//            throw new Exception("操作数量不能为负数");
//        }
//    }
//
//    /**
//     * 单据类型 校验
//     *
//     * @param
//     * @return
//     */
//    private void getDocumentType(String documentType) throws Exception {
//        if (DocumentTypecConfig.isOpen) {
//            if (ObjectUtils.isEmpty(documentType)) {
//                throw new Exception("单据类型不能为空");
//            }
//        }
//    }
//
//    /*   过滤数据
//     * @param inventoryStorageVo
//     * @param inventoryList
//     * @return
//     */
//    private List<Inventory> getInventories(InventoryStorageVo inventoryStorageVo, List<Inventory> inventoryList) {
//        inventoryList = inventoryList.stream().filter(s -> s.getItemId().equals(inventoryStorageVo.getItem().getId())).collect(Collectors.toList());
//        if (inventoryStorageVo.getBatchNo() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getBatchNo() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getBatchNo() != null).filter(s -> s.getBatchNo() != null).filter(s -> s.getBatchNo().equals(inventoryStorageVo.getBatchNo())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getStockId() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getStockId() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getStockId() != null).filter(s -> s.getStockId() != null).filter(s -> s.getStockId().equals(inventoryStorageVo.getStockId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getFnSku() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getFnSku() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getFnSku() != null).filter(s -> s.getFnSku().equals(inventoryStorageVo.getFnSku())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getShopId() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getShopId() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getShopId() != null).filter(s -> s.getShopId().equals(inventoryStorageVo.getShopId())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getExpiryDate() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getExpiryDate() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getExpiryDate()!= null).filter(s -> s.getExpiryDate().equals(inventoryStorageVo.getExpiryDate())).collect(Collectors.toList());
//        }
//        if (inventoryStorageVo.getProjectId() == null) {
//            inventoryList = inventoryList.stream().filter(s -> s.getProjectId() == null).collect(Collectors.toList());
//        } else {
//            inventoryList = inventoryList.stream().filter(s -> s.getProjectId() != null).filter(s -> s.getProjectId().equals(inventoryStorageVo.getProjectId())).collect(Collectors.toList());
//        }
//        return inventoryList;
//    }
//
//    /**
//     * 根据仓库  是否允许负库存 true 允许 false 不允许
//     *
//     * @param
//     * @return
//     */
//    private Boolean getIsOpenNegativeInventory(Long stockId) {
//        Boolean b = true;
//        if (StringUtils.isNotBlank(InventoryConfig.sql)) {
//            try {
//                String sql = String.format(InventoryConfig.sql, stockId);
//                Integer i = inventoryMapper.selectNegativeInventoryCount(sql);
//                if (i > 0) {
//                    return false;
//                }
//            } catch (Exception e) {
//
//            }
//        }
//        return b;
//    }
//    static class ChangeNum {
//        private BigDecimal initValue;
//        private BigDecimal newValue;
//
//        public ChangeNum(BigDecimal initValue) {
//            this.initValue = initValue;
//        }
//
//        public void resetInitValue(BigDecimal initValue) {
//            this.initValue = initValue;
//        }
//
//        public BigDecimal getInitValue() {
//            return initValue;
//        }
//
//        public BigDecimal getNewValue() {
//            return newValue;
//        }
//
//        public void setNewValue(BigDecimal newValue) {
//            this.newValue = newValue;
//        }
//
//        public BigDecimal getValue() {
//            if (newValue != null) {
//                return newValue;
//            }
//            if (initValue != null) {
//                return initValue;
//            }
//            return BigDecimal.ZERO;
//        }
//
//        public BigDecimal add(BigDecimal value) {
//            newValue = orZero(getValue()).add(value);
//            return newValue;
//        }
//
//        public BigDecimal subtract(BigDecimal value) {
//            newValue = orZero(getValue()).subtract(value);
//            return newValue;
//        }
//
//        public BigDecimal getChange() {
//            if (orZero(initValue).equals(orZero(newValue))) {
//                return null;
//            }
//            return orZero(newValue).subtract(orZero(initValue));
//        }
//
//        public BigDecimal getNotNullValue() {
//            return orZero(getValue());
//        }
//
//        public boolean isNegative() {
//            if (newValue != null) {
//                return newValue.compareTo(BigDecimal.ZERO) < 0;
//            }
//            if (initValue != null) {
//                return initValue.compareTo(BigDecimal.ZERO) < 0;
//            }
//            return false;
//        }
//    }
//}
